{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "ee_Image.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": [
        "h-SbkLxfVRa7",
        "u789tt7jtFcI",
        "FfGsJdAhQDgz",
        "EB8yxPAjQJld",
        "gkvA7TdFQZRd",
        "ZZtzMQJEQeAw",
        "DLjJaMMGF68U",
        "eXfJJwRRQnRU",
        "QOxDtzd5tm5u",
        "M2ltWjMZ8c3j",
        "wt2yKCqp-5KE",
        "WNudwwQbEl7J",
        "P3AFSmaXIe_R",
        "3jgKaKuwMzGH",
        "1_5_VmRbPb4D",
        "a4SthZpi4kYt",
        "JTwFpEYGw4BB",
        "lxGo2vW2w-hD",
        "Xt-Xj7tVzVzV"
      ],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_rUp3DC76g8u",
        "colab_type": "text"
      },
      "source": [
        "<!--COURSE_INFORMATION-->\n",
        "<img align=\"left\" style=\"padding-right:10px;\" src=\"https://sitejerk.com/images/google-earth-logo-png-5.png\" width=5% >\n",
        "<img align=\"right\" style=\"padding-left:10px;\" src=\"https://colab.research.google.com/img/colab_favicon_256px.png\" width=6% >\n",
        "\n",
        "\n",
        ">> *This notebook is part of the free course [EEwPython](https://colab.research.google.com/github/csaybar/EEwPython/blob/master/index.ipynb); the content is available [on GitHub](https://github.com/csaybar/EEwPython)* and released under the [Apache 2.0 License](https://www.gnu.org/licenses/gpl-3.0.en.html). 99% of this material has been adapted from [Google Earth Engine Guides](https://developers.google.com/earth-engine/)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "g-iMfR17vqXj",
        "colab_type": "text"
      },
      "source": [
        "<!--NAVIGATION-->\n",
        " < [Developer's Guide](1_Introduction.ipynb) | [Contents](index.ipynb) |  [ImageCollection](3_eeImageCollection.ipynb)>\n",
        "\n",
        "<a href=\"https://colab.research.google.com/github/csaybar/EEwPython/blob/master/3_eeImageCollection.ipynb\"><img align=\"left\" src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\" title=\"Open and Execute in Google Colaboratory\"></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bwe6E7bEnVLa",
        "colab_type": "text"
      },
      "source": [
        "<center>\n",
        "<h1>Google Earth Engine with Python </h1>\n",
        "<h2> ee.Image</h2>\n",
        "</center>\n",
        "<h2> Topics:</h2>\n",
        "\n",
        "1. Image Overview\n",
        "2. Image Visualization\n",
        "3. Image information and metadata\n",
        "4. Mathematical Expressions\n",
        "5. Relational, conditional and Boolean operations\n",
        "6. Convolutions\n",
        "7. Morphological Operations\n",
        "8. Gradients\n",
        "9. Edge Detection\n",
        "10. Spectral Transformations\n",
        "11. Texture\n",
        "12. Object-based Methods\n",
        "13. Cumulative Cost Mapping\n",
        "14. Registering Images"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VxW_4vQjg6tr",
        "colab_type": "text"
      },
      "source": [
        "Raster data are represented as Image objects in Earth Engine. Images are composed of one or more bands and each band has its own name, data type, scale, mask and projection. Each image can have metadata stored as a set of properties (Dictionary)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "u789tt7jtFcI",
        "colab_type": "text"
      },
      "source": [
        "## Connecting GEE with Google Services"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0UH2asC7CB1N",
        "colab_type": "text"
      },
      "source": [
        "- **Authenticate to Earth Engine**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZGbB_ztw-jwR",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install earthengine-api #earth-engine Python API"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "B3ed9DzvCPEU",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!earthengine authenticate "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HV3XrM7Gn65R",
        "colab_type": "text"
      },
      "source": [
        "- **Authenticate to Google Drive (OPTIONAL)**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zT1Vlq2un8pd",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HCuJPiu6ooCX",
        "colab_type": "text"
      },
      "source": [
        "- **Authenticate to Google Cloud (OPTIONAL)**\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oLj8MMeXo0Yg",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from google.colab import auth\n",
        "auth.authenticate_user()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WZf_1vPEX3K0",
        "colab_type": "text"
      },
      "source": [
        "## Testing the software setup\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qhYzUWrCYBrr",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Earth Engine Python API\n",
        "import ee\n",
        "ee.Initialize()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-0ILQ1tvpLes",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import folium\n",
        "\n",
        "# Define the URL format used for Earth Engine generated map tiles.\n",
        "EE_TILES = 'https://earthengine.googleapis.com/map/{mapid}/{{z}}/{{x}}/{{y}}?token={token}'\n",
        "\n",
        "print('Folium version: ' + folium.__version__)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LVFoIUV3kUQg",
        "colab_type": "code",
        "colab": {},
        "cellView": "form"
      },
      "source": [
        "#@title Mapdisplay: Display GEE objects using folium.\n",
        "def Mapdisplay(center, dicc, Tiles=\"OpensTreetMap\",zoom_start=10):\n",
        "    '''\n",
        "    :param center: Center of the map (Latitude and Longitude).\n",
        "    :param dicc: Earth Engine Geometries or Tiles dictionary\n",
        "    :param Tiles: Mapbox Bright,Mapbox Control Room,Stamen Terrain,Stamen Toner,stamenwatercolor,cartodbpositron.\n",
        "    :zoom_start: Initial zoom level for the map.\n",
        "    :return: A folium.Map object.\n",
        "    '''\n",
        "    mapViz = folium.Map(location=center,tiles=Tiles, zoom_start=zoom_start)\n",
        "    for k,v in dicc.items():\n",
        "      if ee.image.Image in [type(x) for x in v.values()]:\n",
        "        folium.TileLayer(\n",
        "            tiles = EE_TILES.format(**v),\n",
        "            attr  = 'Google Earth Engine',\n",
        "            overlay =True,\n",
        "            name  = k\n",
        "          ).add_to(mapViz)\n",
        "      else:\n",
        "        folium.GeoJson(\n",
        "        data = v,\n",
        "        name = k\n",
        "          ).add_to(mapViz)\n",
        "    mapViz.add_child(folium.LayerControl())\n",
        "    return mapViz"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FfGsJdAhQDgz",
        "colab_type": "text"
      },
      "source": [
        "# 1. Image Overview"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qfJ5hLl5tNzh",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "In addition to loading images from the archive by an **image ID**, you can also create images from constants, lists or other suitable Earth Engine objects. This section illustrates methods for creating images, getting band subsets, and manipulating bands.\n",
        "\n",
        "Methods that you will use in this seccion:\n",
        " - **ee.Image.cat**\n",
        " - **ee.Image.addBands**\n",
        " - **ee.Image.Select**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "JL8bXuLov_hE",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# 2.1 Create a constant image.\n",
        "image1 = ee.Image(1)\n",
        "print(image1,'\\n')\n",
        "image1.getInfo()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "z0sBOUeEkeS5",
        "colab_type": "text"
      },
      "source": [
        "- **ee.Image.cat(list)**: Concatenate the given images together into a single image.\n",
        "\n",
        "  "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8emZLqwWhsAE",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#2.2 Concatenate two images into one multi-band image.\n",
        "image2 = ee.Image(2)\n",
        "image3 = ee.Image.cat([image1, image2])\n",
        "print(image3,'\\n')\n",
        "image3.getInfo()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TLw4Ghd3h9MD",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Create a multi-band image from a list of constants.\n",
        "multiband = ee.Image([1, 2, 3])\n",
        "print(multiband,'\\n')\n",
        "multiband.getInfo()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3KpTZWqKh-gV",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Select and (optionally) rename bands.\n",
        "renamed = multiband.select(['constant', 'constant_1', 'constant_2'],\n",
        "                           ['band1', 'band2', 'band3'])\n",
        "print(renamed)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Fffx7suImrOh",
        "colab_type": "text"
      },
      "source": [
        "- **ee.Image.addBands**: Returns an image containing all bands copied from the first input and selected bands from the second input, optionally overwriting bands in the first image with the same name. The new image has the metadata and footprint from the first input image"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CIHOje0qh_r1",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Add bands to an image.\n",
        "image4 = image3.addBands(ee.Image(42))\n",
        "print(image4)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "EB8yxPAjQJld",
        "colab_type": "text"
      },
      "source": [
        "# 2. Image Vizualization"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FdD1dnNInVuw",
        "colab_type": "text"
      },
      "source": [
        "The Python API  a difference than the Code Editor do not support interactive vizualization (**Map.addLayer**). To achieve desirable visualization effects you could use **ee.Image.getThumbURL** in replacement of Map.addLayer. Both  ee.Image.getThumbURL and Map.addLayer have the same parameters:\n",
        "\n",
        "\n",
        "\n",
        "Parameter | Description | Type\n",
        "--------------|-------------|-------------\n",
        "bands\t| Comma-delimited list of three band names to be mapped to RGB| list\n",
        "min|\tValue(s) to map to 0\tnumber or list of three numbers, one for each |band\n",
        "max|\tValue(s) to map to 255\t|number or list of three numbers, one for each band\n",
        "gain|\tValue(s) by which to multiply each pixel value|\tnumber or list of three numbers, one for each band\n",
        "bias|\tValue(s) to add to each DN\t| number or list of three numbers, one for each band\n",
        "gamma|\tGamma correction factor(s)\t| number or list of three numbers, one for each band\n",
        "palette|\tList of CSS-style color strings (single-band images only)\t|comma-separated list of hex strings\n",
        "opacity|\tThe opacity of the layer (0.0 is fully transparent and 1.0 is fully opaque)\t| number\n",
        "format|\tEither \"jpg\" or \"png\"\t|string"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3U6Gcw4Ing2m",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "0c73d3f7-a90e-4277-c100-82dcd25ec9cf"
      },
      "source": [
        "# Load an image.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n",
        "mapid = image.getMapId({\n",
        "    'bands': ['B4', 'B3', 'B2'], \n",
        "    'min': 0, \n",
        "    'max': 0.3})\n",
        "\n",
        "# Display the map with folium!\n",
        "Mapdisplay(center, {'Median Composite':mapid},zoom_start=8)"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text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iMGI3YWY3ZDU3YjRlZThhNDI3ZTE4OTk1ODA3ODFlLCB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiB7ICJNZWRpYW4gQ29tcG9zaXRlIiA6IHRpbGVfbGF5ZXJfZjVmZjVjZGNkMmJjNGFmZDg5ZDEwMzYwZWQ0NjFjMTUsIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgIEwuY29udHJvbC5sYXllcnMoCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzhhYTg0NTFiOTE3ODQ1ZjRhOTZmZDQ1MjhlNGZkMTJjLmJhc2VfbGF5ZXJzLAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF84YWE4NDUxYjkxNzg0NWY0YTk2ZmQ0NTI4ZTRmZDEyYy5vdmVybGF5cywKICAgICAgICAgICAgICAgIHtwb3NpdGlvbjogJ3RvcHJpZ2h0JywKICAgICAgICAgICAgICAgICBjb2xsYXBzZWQ6IHRydWUsCiAgICAgICAgICAgICAgICAgYXV0b1pJbmRleDogdHJ1ZQogICAgICAgICAgICAgICAgfSkuYWRkVG8obWFwXzM0YzhiYzkyYzgzMTQwZmZhZTA0ZjU5M2QzNmM2NGU5KTsKICAgICAgICAgICAgCiAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd18937828>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AlsSAlP11WZS",
        "colab_type": "text"
      },
      "source": [
        "## Masking\n",
        "\n",
        "You can use **`image.updateMask()`** to set the opacity of individual pixels based on where pixels in a mask image are non-zero. Pixels equal to zero in the mask are excluded from computations and the opacity is set to 0 for display. The following example uses an NDWI threshold (see the [Relational Operations section]() for information on thresholds) to update the mask on the NDWI layer created previously:\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "frBqSRZr1gBh",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "b572bbd8-cef6-4037-a0ae-9d25ecfd32c1"
      },
      "source": [
        "# Load an image.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n",
        "\n",
        "# Create an NDWI image, define visualization parameters and display.\n",
        "ndwi = image.normalizedDifference(['B3', 'B5'])\n",
        "\n",
        "# Mask the non-watery parts of the image, where NDWI < 0.4.\n",
        "ndwiMasked = ndwi.updateMask(ndwi.gte(0.4))\n",
        "ndwiId = ndwiMasked.getMapId({'min': 0.5, 'max': 1, 'palette': ['00FFFF', '0000FF']})\n",
        "\n",
        "# Display the map with folium!\n",
        "center=[38., -122.5]\n",
        "Mapdisplay(center,{'NDWI masked':ndwiId})"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9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naHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfY2E0Nzk0ZTFjZjI2NDNkZmJmOGZmYTUyMzVkMTBkMTcpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd189e31d0>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "SrMMdKzj4xqu",
        "colab_type": "text"
      },
      "source": [
        "## Clipping\n",
        "\n",
        "The **`image.clip()`** method is useful for achieving cartographic effects. The following example clips the Image **RGB_SF**."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jpIuRQz15McL",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "ff355142-05f7-4f0a-e2cf-90bcf8137f22"
      },
      "source": [
        "# Create a circle by drawing a 20000 meter buffer around a point.\n",
        "roi = ee.Geometry.Point([-122.4481, 37.7599]).buffer(20000)\n",
        "\n",
        "mapRoi = image.clip(roi)\n",
        "mapId = mapRoi.getMapId()\n",
        "\n",
        "# Display map\n",
        "center=[38., -122.5]\n",
        "Mapdisplay(center,{'Mosaic':mapId})"
      ],
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1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NjA2MmZiNzBhNDAxMThmM2I2OTYxZjY2MzVmOGUsIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgIEwuY29udHJvbC5sYXllcnMoCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzU2MzVmNmMyMzkyNjQwNzNhODM1Mjk1YzU0ZjcxNTA5LmJhc2VfbGF5ZXJzLAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF81NjM1ZjZjMjM5MjY0MDczYTgzNTI5NWM1NGY3MTUwOS5vdmVybGF5cywKICAgICAgICAgICAgICAgIHtwb3NpdGlvbjogJ3RvcHJpZ2h0JywKICAgICAgICAgICAgICAgICBjb2xsYXBzZWQ6IHRydWUsCiAgICAgICAgICAgICAgICAgYXV0b1pJbmRleDogdHJ1ZQogICAgICAgICAgICAgICAgfSkuYWRkVG8obWFwXzdhMDQ4NWM1ZjcwODQ0YmQ4YWFmZTljYjA2ZDY3MzM0KTsKICAgICAgICAgICAgCiAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd188e17b8>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "T_xUM23o5eBo",
        "colab_type": "text"
      },
      "source": [
        "## Rendering categorical maps\n",
        "\n",
        "Palettes are also useful for rendering discrete valued maps, for example a land cover map. In the case of multiple classes, use the palette to supply a different color for each class. (The **`image.remap()`** method may be useful in this context, to convert arbitrary labels to consecutive integers). The following example uses a palette to render land cover categories:\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wJqDl2S65hvw",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "3adb8435-7430-4298-8c8a-08f1c37c52fe"
      },
      "source": [
        "cover = ee.Image('MODIS/051/MCD12Q1/2012_01_01').select('Land_Cover_Type_1')\n",
        "\n",
        "# Define a palette for the 18 distinct land cover classes.\n",
        "igbpPalette = [\n",
        "  'aec3d4', # water\n",
        "  '152106', '225129', '369b47', '30eb5b', '387242', # forest\n",
        "  '6a2325', 'c3aa69', 'b76031', 'd9903d', '91af40',  # shrub, grass\n",
        "  '111149', # wetlands\n",
        "  'cdb33b', # croplands\n",
        "  'cc0013', # urban\n",
        "  '33280d', # crop mosaic\n",
        "  'd7cdcc', # snow and ice\n",
        "  'f7e084', # barren\n",
        "  '6f6f6f'  # tundra\n",
        "]\n",
        "\n",
        "# Specify the min and max labels and the color palette matching the labels.\n",
        "vizParams = {'min': 0,\n",
        "             'max': 17,\n",
        "             'palette': igbpPalette}\n",
        "mapId = cover.getMapId(vizParams)\n",
        "\n",
        "#Display the map with folium!\n",
        "center = [38., -122.5]\n",
        "Mapdisplay(center,{'Mosaic':mapId},zoom_start=8)"
      ],
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9q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vc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfZDVjN2IzOGY4MDcwNGM3MGFhYjM3Mzc5ZDBmMjIwMzgpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd18928b70>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gkvA7TdFQZRd",
        "colab_type": "text"
      },
      "source": [
        "# 3. Image information and metadata"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "QInLa5g88rUG",
        "colab_type": "text"
      },
      "source": [
        "To explore image bands and properties in the Python API, getInfo() the image and inspect the output in the console. This information can also be accessed programmatically. For example, the following demonstrates how to access information about bands, projections and other metadata:\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "29eygRFu8id7",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "9d3a5afe-2f09-40fd-abf1-f6e34bb21a9d"
      },
      "source": [
        "# Load an image.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318')\n",
        "\n",
        "# Get information about the bands as a list.\n",
        "bandNames = image.bandNames()\n",
        "print('Band names: ', bandNames.getInfo()) # ee.List of band names"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Band names:  ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10', 'B11', 'BQA']\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gT2sTonS-67R",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        },
        "outputId": "1e44c3d1-d24e-4ef9-d3d6-d6f972bc2575"
      },
      "source": [
        "# Get projection information from band 1.\n",
        "b1proj = image.select('B1').projection()\n",
        "print('Band 1 projection: \\n', b1proj.getInfo()) # ee.Projection object"
      ],
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Band 1 projection: \n",
            " {'type': 'Projection', 'crs': 'EPSG:32610', 'transform': [30.0, 0.0, 460785.0, 0.0, -30.0, 4264215.0]}\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VOv5uU7D-8P6",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        },
        "outputId": "d4bf2295-8d32-4128-bc58-ed9659836206"
      },
      "source": [
        "# Get scale (in meters) information from band 1.\n",
        "b1scale = image.select('B1').projection().nominalScale()\n",
        "print('Band 1 scale: \\n', b1scale.getInfo()) # ee.Number"
      ],
      "execution_count": 23,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Band 1 scale: \n",
            " 30.0\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ME1zxhV6-9GV",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        },
        "outputId": "ad3ac9cc-58c5-4f77-b952-a94b27056440"
      },
      "source": [
        "# Note that different bands can have different projections and scale.\n",
        "b8scale = image.select('B8').projection().nominalScale()\n",
        "print('Band 8 scale: \\n', b8scale.getInfo()) # ee.Number"
      ],
      "execution_count": 24,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Band 8 scale: \n",
            " 15.0\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-pEdDfTV--OA",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 2108
        },
        "outputId": "990ed22f-d827-44e1-803a-085adc9a5fce"
      },
      "source": [
        "# Get a list of all metadata properties.\n",
        "properties = image.propertyNames()\n",
        "print('Metadata properties:', ) \n",
        "properties.getInfo() # ee.List of metadata properties"
      ],
      "execution_count": 25,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Metadata properties:\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['RADIANCE_MULT_BAND_5',\n",
              " 'RADIANCE_MULT_BAND_6',\n",
              " 'RADIANCE_MULT_BAND_3',\n",
              " 'RADIANCE_MULT_BAND_4',\n",
              " 'RADIANCE_MULT_BAND_1',\n",
              " 'RADIANCE_MULT_BAND_2',\n",
              " 'system:id',\n",
              " 'K2_CONSTANT_BAND_11',\n",
              " 'K2_CONSTANT_BAND_10',\n",
              " 'system:footprint',\n",
              " 'REFLECTIVE_SAMPLES',\n",
              " 'SUN_AZIMUTH',\n",
              " 'CPF_NAME',\n",
              " 'DATE_ACQUIRED',\n",
              " 'ELLIPSOID',\n",
              " 'google:registration_offset_x',\n",
              " 'google:registration_offset_y',\n",
              " 'STATION_ID',\n",
              " 'RESAMPLING_OPTION',\n",
              " 'ORIENTATION',\n",
              " 'WRS_ROW',\n",
              " 'RADIANCE_MULT_BAND_9',\n",
              " 'TARGET_WRS_ROW',\n",
              " 'RADIANCE_MULT_BAND_7',\n",
              " 'RADIANCE_MULT_BAND_8',\n",
              " 'IMAGE_QUALITY_TIRS',\n",
              " 'TRUNCATION_OLI',\n",
              " 'CLOUD_COVER',\n",
              " 'GEOMETRIC_RMSE_VERIFY',\n",
              " 'COLLECTION_CATEGORY',\n",
              " 'GRID_CELL_SIZE_REFLECTIVE',\n",
              " 'CLOUD_COVER_LAND',\n",
              " 'GEOMETRIC_RMSE_MODEL',\n",
              " 'COLLECTION_NUMBER',\n",
              " 'IMAGE_QUALITY_OLI',\n",
              " 'LANDSAT_SCENE_ID',\n",
              " 'WRS_PATH',\n",
              " 'google:registration_count',\n",
              " 'PANCHROMATIC_SAMPLES',\n",
              " 'PANCHROMATIC_LINES',\n",
              " 'GEOMETRIC_RMSE_MODEL_Y',\n",
              " 'REFLECTIVE_LINES',\n",
              " 'TIRS_STRAY_LIGHT_CORRECTION_SOURCE',\n",
              " 'GEOMETRIC_RMSE_MODEL_X',\n",
              " 'system:asset_size',\n",
              " 'system:index',\n",
              " 'REFLECTANCE_ADD_BAND_1',\n",
              " 'REFLECTANCE_ADD_BAND_2',\n",
              " 'DATUM',\n",
              " 'REFLECTANCE_ADD_BAND_3',\n",
              " 'REFLECTANCE_ADD_BAND_4',\n",
              " 'RLUT_FILE_NAME',\n",
              " 'REFLECTANCE_ADD_BAND_5',\n",
              " 'REFLECTANCE_ADD_BAND_6',\n",
              " 'REFLECTANCE_ADD_BAND_7',\n",
              " 'REFLECTANCE_ADD_BAND_8',\n",
              " 'BPF_NAME_TIRS',\n",
              " 'system:version',\n",
              " 'GROUND_CONTROL_POINTS_VERSION',\n",
              " 'DATA_TYPE',\n",
              " 'UTM_ZONE',\n",
              " 'LANDSAT_PRODUCT_ID',\n",
              " 'REFLECTANCE_ADD_BAND_9',\n",
              " 'google:registration_ratio',\n",
              " 'GRID_CELL_SIZE_PANCHROMATIC',\n",
              " 'RADIANCE_ADD_BAND_4',\n",
              " 'REFLECTANCE_MULT_BAND_7',\n",
              " 'system:time_start',\n",
              " 'RADIANCE_ADD_BAND_5',\n",
              " 'REFLECTANCE_MULT_BAND_6',\n",
              " 'RADIANCE_ADD_BAND_6',\n",
              " 'REFLECTANCE_MULT_BAND_9',\n",
              " 'PROCESSING_SOFTWARE_VERSION',\n",
              " 'RADIANCE_ADD_BAND_7',\n",
              " 'REFLECTANCE_MULT_BAND_8',\n",
              " 'RADIANCE_ADD_BAND_1',\n",
              " 'RADIANCE_ADD_BAND_2',\n",
              " 'RADIANCE_ADD_BAND_3',\n",
              " 'REFLECTANCE_MULT_BAND_1',\n",
              " 'RADIANCE_ADD_BAND_8',\n",
              " 'REFLECTANCE_MULT_BAND_3',\n",
              " 'RADIANCE_ADD_BAND_9',\n",
              " 'REFLECTANCE_MULT_BAND_2',\n",
              " 'REFLECTANCE_MULT_BAND_5',\n",
              " 'REFLECTANCE_MULT_BAND_4',\n",
              " 'THERMAL_LINES',\n",
              " 'TIRS_SSM_POSITION_STATUS',\n",
              " 'GRID_CELL_SIZE_THERMAL',\n",
              " 'NADIR_OFFNADIR',\n",
              " 'RADIANCE_ADD_BAND_11',\n",
              " 'REQUEST_ID',\n",
              " 'EARTH_SUN_DISTANCE',\n",
              " 'TIRS_SSM_MODEL',\n",
              " 'FILE_DATE',\n",
              " 'SCENE_CENTER_TIME',\n",
              " 'SUN_ELEVATION',\n",
              " 'BPF_NAME_OLI',\n",
              " 'RADIANCE_ADD_BAND_10',\n",
              " 'ROLL_ANGLE',\n",
              " 'K1_CONSTANT_BAND_10',\n",
              " 'SATURATION_BAND_1',\n",
              " 'SATURATION_BAND_2',\n",
              " 'SATURATION_BAND_3',\n",
              " 'SATURATION_BAND_4',\n",
              " 'SATURATION_BAND_5',\n",
              " 'MAP_PROJECTION',\n",
              " 'SATURATION_BAND_6',\n",
              " 'SENSOR_ID',\n",
              " 'SATURATION_BAND_7',\n",
              " 'K1_CONSTANT_BAND_11',\n",
              " 'SATURATION_BAND_8',\n",
              " 'SATURATION_BAND_9',\n",
              " 'TARGET_WRS_PATH',\n",
              " 'RADIANCE_MULT_BAND_11',\n",
              " 'RADIANCE_MULT_BAND_10',\n",
              " 'GROUND_CONTROL_POINTS_MODEL',\n",
              " 'SPACECRAFT_ID',\n",
              " 'ELEVATION_SOURCE',\n",
              " 'THERMAL_SAMPLES',\n",
              " 'GROUND_CONTROL_POINTS_VERIFY',\n",
              " 'system:bands',\n",
              " 'system:band_names']"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 25
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SJIOLkne-_MA",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        },
        "outputId": "39869818-88bb-435d-ce1f-2bd2da5fe239"
      },
      "source": [
        "# Get a specific metadata property.\n",
        "cloudiness = image.get('CLOUD_COVER')\n",
        "print('CLOUD_COVER: ')\n",
        "cloudiness.getInfo() # ee.Number"
      ],
      "execution_count": 26,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "CLOUD_COVER: \n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.06"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 26
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-XrdBSXs_AR5",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "1653436c-705c-407f-e83d-9296f9d58b1d"
      },
      "source": [
        "from datetime import datetime as dt\n",
        "\n",
        "# Get the timestamp and convert it to a date.\n",
        "date = ee.Date(image.get('system:time_start'))\n",
        "# We divide by 1000 because Earth Engine returns the timestamp in milisecond and Python in seconds.\n",
        "tmstp = date.getInfo()['value']/1000 \n",
        "\n",
        "print('Timestamp:', dt.utcfromtimestamp(tmstp).strftime('%Y-%m-%d %H:%M:%S'))"
      ],
      "execution_count": 27,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Timestamp: 2014-03-18 18:46:32\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9OOhM1j_BrYy",
        "colab_type": "text"
      },
      "source": [
        "Note that the results of these queries are **server-side objects**. When you use the method \\*.getInfo(), you request that information describing the object be sent from the server to your client. (Learn more about client vs. server in Earth Engine on this [page](https://developers.google.com/earth-engine/client_server)). \n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZZtzMQJEQeAw",
        "colab_type": "text"
      },
      "source": [
        "# 4. Mathematical Expressions"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5T1btubjBoLG",
        "colab_type": "text"
      },
      "source": [
        "Earth Engine supports many basic mathematical operators. They share some common features. **Earth Engine performs math operations per pixel**. When an operator is applied to an image, it's applied to each unmasked pixel of each band. In the case of operations on two images, the operation is only applied at the locations where pixels in both images are unmasked. Earth Engine automatically matches bands between images. When an operator is applied to two images, the images are expected to have the same number of bands so they can be matched pairwise. However, if one of the images has only a single band, it is matched with all of the bands in the other image, essentially replicating that band enough times to match the other image.\n",
        "\n",
        "\n",
        "For a simple example, consider the task of creating the Normalized Difference Vegetation Index (NDVI) using Landsat imagery:\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wKc4Ma-UChy2",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "12169936-8320-4e76-8754-8c9801bbedca"
      },
      "source": [
        "# Load two 5-year Landsat 7 composites.\n",
        "landsat1999 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003')\n",
        "landsat2008 = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012')\n",
        "\n",
        "# Compute NDVI the hard way.\n",
        "ndvi1999 = landsat1999.select('B4')\\\n",
        "                      .subtract(landsat1999.select('B3'))\\\n",
        "                      .divide(landsat1999.select('B4').add(landsat1999.select('B3')))\n",
        "\n",
        "# Compute NDVI the easy way.\n",
        "ndvi2008 = landsat2008.normalizedDifference(['B4', 'B3'])\n",
        "\n",
        "#Vizualization\n",
        "ndwiViz = {'min': 0, 'max': 1, 'palette': ['FF0000', '00FF00']}\n",
        "Peru = ee.Geometry.Rectangle(-85, -20, -65,0) \n",
        "\n",
        "ndvi1999 = ndvi1999.clip(Peru)\n",
        "ndvi2008 = ndvi2008.clip(Peru)\n",
        "\n",
        "tiles = {\n",
        "    \"NDVI PERU 1999\": ndvi1999.getMapId(ndwiViz), \n",
        "    \"NDVI PERU 2008\": ndvi2008.getMapId(ndwiViz)\n",
        "}\n",
        "center = [-12., -75.]\n",
        "Mapdisplay(center, tiles)"
      ],
      "execution_count": 28,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsg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fQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfMjJlYWFhMzc4MDQ0NGFiNzk2YjYyMGVlZTQzMTVkYjQuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzIyZWFhYTM3ODA0NDRhYjc5NmI2MjBlZWU0MzE1ZGI0Lm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfMGI1NmY5ZGVkN2RlNGIyNWI3ZWIzZjIzYTcwMWM3YTcpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd188fd780>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 28
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "DLjJaMMGF68U",
        "colab_type": "text"
      },
      "source": [
        "####  Expressions\n",
        "\n",
        "To implement more complex mathematical expressions, it may be more convenient to use **`image.expression()`**, which parses a text representation of a math operation. The following example uses **`expression()`** to compute the Enhanced Vegetation Index (EVI):"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LYxu202kFz85",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "8ac6e554-e96c-4fcb-83c9-8e60043f5730"
      },
      "source": [
        "# Load a Landsat 8 image.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n",
        "\n",
        "# Compute the EVI using an expression.\n",
        "evi = image.expression(\n",
        "      '2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {\n",
        "      'NIR': image.select('B5'),\n",
        "      'RED': image.select('B4'),\n",
        "      'BLUE': image.select('B2')})\n",
        "\n",
        "#Display the map with folium!\n",
        "Eviviz = {'min': 0, 'max': 1, 'palette': ['FF0000', '00FF00']}\n",
        "tiles = {\"EVI 2014\": evi.getMapId(Eviviz)}\n",
        "\n",
        "center  = [37,-122]\n",
        "Mapdisplay(center, tiles)"
      ],
      "execution_count": 30,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4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4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd188eed30>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 30
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3MgoiRlGTtWG",
        "colab_type": "text"
      },
      "source": [
        "Observe that the first argument to expression is the textual representation of the math operation, the second argument is a dictionary where the keys are variable names used in the expression and the values are the image bands to which the variables should be mapped. Bands in the image may be referred to as `b(\"band name\")` or `b(index)`, for example `b(0)`, instead of providing the dictionary. Note that division functions as it does in Python: dividing two integers results in an integer. For example `10 / 20 = 0`. To change this behavior, multiply one of the operands by `1.0: 10 * 1.0 / 20 = 0.5`. Supported expression operators are listed in the following table.\n",
        "\n",
        " _ | _ | Operators for expression()\n",
        "--------------|-------------|-------------\n",
        "Arithmetic\t|+ - * / % **\t|Add, Subtract, Multiply, Divide, Modulus, Exponent\n",
        "Comparison\t| == != < > <= >= |\tEqual, Not Equal, Less Than, Greater than, etc.\n",
        "Logical |\t&& \\|\\| ! ^\t| And, Or, Not, Xor\n",
        "Ternary\t| ? :\t| If then else"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "eXfJJwRRQnRU",
        "colab_type": "text"
      },
      "source": [
        "# 5. Relational, conditional and Boolean operations"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mn6nSZnrQnOp",
        "colab_type": "text"
      },
      "source": [
        "To perform per-pixel comparisons between images, use relational operators. To extract urbanized areas in an image, this example uses relational operators to threshold spectral indices, combining the thresholds with and():"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Bcb_qgvM3Q-a",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "77a0f35f-c4ad-4e58-ae2c-cbb2a62d9729"
      },
      "source": [
        "# Load a Landsat 8 image.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n",
        "\n",
        "# Create NDVI and NDWI spectral indices.\n",
        "ndvi = image.normalizedDifference(['B5', 'B4'])\n",
        "ndwi = image.normalizedDifference(['B3', 'B5'])\n",
        "\n",
        "# Create a binary layer using logical operations.\n",
        "bare = ndvi.lt(0.2).And(ndwi.lt(0))\n",
        "\n",
        "bare = bare.updateMask(bare)\n",
        "BareId = bare.getMapId()\n",
        "\n",
        "tiles = {\"Bare\": BareId}\n",
        "center = [37.7726, -122.3578]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 31,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaX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gICAgICAiZGV0ZWN0UmV0aW5hIjogZmFsc2UsCiAgICAgICAgIm1heE5hdGl2ZVpvb20iOiAxOCwKICAgICAgICAibWF4Wm9vbSI6IDE4LAogICAgICAgICJtaW5ab29tIjogMCwKICAgICAgICAibm9XcmFwIjogZmFsc2UsCiAgICAgICAgIm9wYWNpdHkiOiAxLAogICAgICAgICJzdWJkb21haW5zIjogImFiYyIsCiAgICAgICAgInRtcyI6IGZhbHNlCn0pLmFkZFRvKG1hcF80NzBiMGM3Mjg4ODk0OTgyOTkxNDE0MDFjZjFkYTQ0ZCk7CiAgICAKICAgICAgICAgICAgdmFyIGxheWVyX2NvbnRyb2xfMTYxZmZjMmUwNzEzNDkzMTkxNDk1MjZiMGI4ZmNkZDEgPSB7CiAgICAgICAgICAgICAgICBiYXNlX2xheWVycyA6IHsgInN0YW1lbnRlcnJhaW4iIDogdGlsZV9sYXllcl8xM2U3MDM5NDg0ODY0NzgyYmQ5ZDViYTExODcwNDE1MCwgfSwKICAgICAgICAgICAgICAgIG92ZXJsYXlzIDogeyAiQmFyZSIgOiB0aWxlX2xheWVyX2RmNmYyOGFkYTg4ZTQ4MjZiMTkzOTAzNDFhMGM1OTgxLCB9CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF8xNjFmZmMyZTA3MTM0OTMxOTE0OTUyNmIwYjhmY2RkMS5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfMTYxZmZjMmUwNzEzNDkzMTkxNDk1MjZiMGI4ZmNkZDEub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7cG9zaXRpb246ICd0b3ByaWdodCcsCiAgICAgICAgICAgICAgICAgY29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF80NzBiMGM3Mjg4ODk0OTgyOTkxNDE0MDFjZjFkYTQ0ZCk7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd188ee390>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 31
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "BXVPhUv3FBUI",
        "colab_type": "text"
      },
      "source": [
        "As illustrated by this example, the output of relational and boolean operators is either true (1) or false (0). To mask the 0's, you can mask the resultant binary image with itself. The result from the previous example should look something.\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MtCLrkVYFRn3",
        "colab_type": "text"
      },
      "source": [
        "The binary images that are returned by relational and boolean operators can be used with mathematical operators. This example creates zones of urbanization in a nighttime lights image using relational operators and image.add():\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0Srflh5jFcAE",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "5258342c-299c-4620-bc35-e98347e46e4f"
      },
      "source": [
        "# Load a 2012 nightlights image.\n",
        "nl2012 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182012')\n",
        "lights = nl2012.select('stable_lights')\n",
        "\n",
        "# Define arbitrary thresholds on the 6-bit stable lights band.\n",
        "zones = lights.gt(30).add(lights.gt(55)).add(lights.gt(62))\n",
        "\n",
        "# Display the thresholded image as three distinct zones near Paris.\n",
        "palette = ['000000', '0000FF', '00FF00', 'FF0000']\n",
        "center = [48.8683, 2.373]\n",
        "\n",
        "zonesId = zones.getMapId({'min': 0, 'max': 3, 'palette': palette})\n",
        "tiles = {\"Zonas\": zonesId}\n",
        "\n",
        "Mapdisplay(center, tiles)"
      ],
      "execution_count": 32,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL21heGNkbi5ib290c3RyYXBjZG4uY29tL2Jvb3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NDI5YyA9IHsKICAgICAgICAgICAgICAgIGJhc2VfbGF5ZXJzIDogeyAib3BlbnN0cmVldG1hcCIgOiB0aWxlX2xheWVyX2Q2MzQ2NWZkMjQxOTRmZTU4NTEyODVlNjIxN2M5NWU2LCB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiB7ICJab25hcyIgOiB0aWxlX2xheWVyXzE4OWI0NzAyOTExNTQ3Zjk5YjFmZjM5Mjk5YTY4MDYxLCB9CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF81OTQ1ZWNkN2ZmMjQ0YjQwOTY2OThjMjE1ZDQ1NDI5Yy5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfNTk0NWVjZDdmZjI0NGI0MDk2Njk4YzIxNWQ0NTQyOWMub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7cG9zaXRpb246ICd0b3ByaWdodCcsCiAgICAgICAgICAgICAgICAgY29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF80MTBjMDgzNGY3NWE0YTYyODYwNDdjYTI2NTExMjViZSk7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd188c9668>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 32
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-9pRgxtuJW79",
        "colab_type": "text"
      },
      "source": [
        "Note that the code in the previous example is equivalent to using a ternary operator implemented by expression()\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HicEUye6Jchu",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "1981e06b-3d04-4ed3-a23a-0359701106e7"
      },
      "source": [
        "zonesExp = nl2012.expression(\"(b('stable_lights') > 62) ? 3: (b('stable_lights') > 55) ? 2: (b('stable_lights') > 30) ? 1: 0\")\n",
        "\n",
        "zonesId = zonesExp.getMapId({'min': 0, 'max': 3, 'palette': palette})\n",
        "tiles = {\"Zonas\": zonesId}\n",
        "\n",
        "Mapdisplay(center, tiles)"
      ],
      "execution_count": 33,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xp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L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd188c9630>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 33
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jGIUEpVNMUMc",
        "colab_type": "text"
      },
      "source": [
        "Another way to implement conditional operations on images is with the image.where() operator. Consider the need to replace masked pixels with some other data. In the following example, cloudy pixels are replaced by pixels from a cloud-free image using where()"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CK9dJzHuNNso",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "33c47f33-7cdc-4c04-ae23-9004268baa42"
      },
      "source": [
        "# Load a cloudy Landsat 8 image.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20130603')\n",
        "\n",
        "# Load another image to replace the cloudy pixels.\n",
        "replacement = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20130416')\n",
        "\n",
        "# Compute a cloud score band.\n",
        "cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud')\n",
        "\n",
        "# Set cloudy pixels to the other image.\n",
        "replaced = image.where(cloud.gt(10), replacement)\n",
        "\n",
        "# Display the result.\n",
        "replacedId = replaced.getMapId({'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5})\n",
        "\n",
        "tiles = {\"Clouds replaced\": replacedId}\n",
        "\n",
        "center = [37.5419, -121.9872]\n",
        "Mapdisplay(center, tiles)"
      ],
      "execution_count": 35,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgI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ICAgICAgICAgIG92ZXJsYXlzIDogeyAiQ2xvdWRzIHJlcGxhY2VkIiA6IHRpbGVfbGF5ZXJfYWExYWRjZjNhM2FiNGQxMzg0ZGY4MWEyYWFmODgzNWEsIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgIEwuY29udHJvbC5sYXllcnMoCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sX2IwZmIxNzM5MjdlYTRiNTE4Y2RhNzhmOTU3YWViOTQ5LmJhc2VfbGF5ZXJzLAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF9iMGZiMTczOTI3ZWE0YjUxOGNkYTc4Zjk1N2FlYjk0OS5vdmVybGF5cywKICAgICAgICAgICAgICAgIHtwb3NpdGlvbjogJ3RvcHJpZ2h0JywKICAgICAgICAgICAgICAgICBjb2xsYXBzZWQ6IHRydWUsCiAgICAgICAgICAgICAgICAgYXV0b1pJbmRleDogdHJ1ZQogICAgICAgICAgICAgICAgfSkuYWRkVG8obWFwXzhiM2M5MTU3NjJkZjRlMDVhNTA5YWUwOTY4YzVmMzczKTsKICAgICAgICAgICAgCiAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd18937cc0>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 35
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1NnJrDesNmyq",
        "colab_type": "text"
      },
      "source": [
        "In this example, observe the use of the simpleCloudScore() algorithm. This algorithm ranks pixels by cloudiness on a scale of 0-100, with 100 most cloudy. Learn more about simpleCloudScore() on the Landsat Algorithms page."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "QOxDtzd5tm5u",
        "colab_type": "text"
      },
      "source": [
        "# 6. Convolutions"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5YTQPZDGt5a5",
        "colab_type": "text"
      },
      "source": [
        "To perform linear convolutions on images, use **image.convolve()**. The only argument to convolve is an ee.Kernel which is specified by a shape and the weights in the kernel. Each pixel of the image output by **convolve()** is the linear combination of the kernel values and the input image pixels covered by the kernel. The kernels are applied to each band individually. For example, you might want to use a low-pass (smoothing) kernel to remove high-frequency information. The following illustrates a 15x15 low-pass kernel applied to a Landsat 8 image"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pNmxQNISt8iC",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 690
        },
        "outputId": "c0d86732-7c45-42be-cdbf-cc5487a3c543"
      },
      "source": [
        "# Load and display an image\n",
        "image   = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n",
        "\n",
        "# Define a boxcar or low-pass kernel\n",
        "boxcar  = ee.Kernel.square(7, 'pixels', True)\n",
        "\n",
        "# Smooth the image by convolving with the boxcar kernel\n",
        "smooth = image.convolve(boxcar)\n",
        "  \n",
        "tiles = {\n",
        "    \"input image\": image.getMapId({'bands': ['B5', 'B4', 'B3'], 'max': 0.5}),\n",
        "    \"smoothed\": smooth.getMapId({'bands': ['B5', 'B4', 'B3'], 'max': 0.5})\n",
        "}\n",
        "\n",
        "center = [37.8694, -121.9785]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 36,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9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5hIjogZmFsc2UsCiAgICAgICAgIm1heE5hdGl2ZVpvb20iOiAxOCwKICAgICAgICAibWF4Wm9vbSI6IDE4LAogICAgICAgICJtaW5ab29tIjogMCwKICAgICAgICAibm9XcmFwIjogZmFsc2UsCiAgICAgICAgIm9wYWNpdHkiOiAxLAogICAgICAgICJzdWJkb21haW5zIjogImFiYyIsCiAgICAgICAgInRtcyI6IGZhbHNlCn0pLmFkZFRvKG1hcF9kOGJhOGZmNjA1NWU0YzA2OWYwZThhZGE0NWIyYTUzYik7CiAgICAKICAgICAgICAgICAgdmFyIGxheWVyX2NvbnRyb2xfOTQxOWZlN2IxY2MzNGIyY2ExYTU0NTAwZTQyMGY0YWMgPSB7CiAgICAgICAgICAgICAgICBiYXNlX2xheWVycyA6IHsgInN0YW1lbnRlcnJhaW4iIDogdGlsZV9sYXllcl9hYTY0NTM5NjFmZDY0YTc0YmRiZDI0NjAzYmJiNGMxYiwgfSwKICAgICAgICAgICAgICAgIG92ZXJsYXlzIDogeyAiaW5wdXQgaW1hZ2UiIDogdGlsZV9sYXllcl82ZTVlN2YwMWQ1MmI0YzI5YTAwMDYxMTFmODJlYWFjNiwic21vb3RoZWQiIDogdGlsZV9sYXllcl80YWU5YTUwMGFjMmI0ZjU5Yjc2MmMyZTdiMmJkZDRlMiwgfQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfOTQxOWZlN2IxY2MzNGIyY2ExYTU0NTAwZTQyMGY0YWMuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzk0MTlmZTdiMWNjMzRiMmNhMWE1NDUwMGU0MjBmNGFjLm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfZDhiYThmZjYwNTVlNGMwNjlmMGU4YWRhNDViMmE1M2IpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd1886e160>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 36
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dlqAjHwg1tJs",
        "colab_type": "text"
      },
      "source": [
        "The output of convolution with the low-pass filter should look something like figure on top. Observe that the arguments to the kernel determine its size and coefficients. Specifically, with the units parameter set to pixels, the radius parameter specifies the number of pixels from the center that the kernel will cover. If normalize is set to true, the kernel coefficients will sum to one. If the magnitude parameter is set, the kernel coefficients will be multiplied by the magnitude (if normalize is also true, the coefficients will sum to magnitude). If there is a negative value in any of the kernel coefficients, setting normalize to true will make the coefficients sum to zero."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GRDxW0Zb2H1H",
        "colab_type": "text"
      },
      "source": [
        "Use other kernels to achieve the desired image processing effect. This example uses a Laplacian kernel for isotropic edge detection"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HW-sijry2zio",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "b6b88534-b050-4bdb-8253-de74bc50507b"
      },
      "source": [
        "# Define a Laplacian, or edge-detection kernel.\n",
        "laplacian = ee.Kernel.laplacian8(normalize = False)\n",
        "\n",
        "# Apply the edge-detection kernel.\n",
        "edgy = image.convolve(laplacian)\n",
        "  \n",
        "tiles = {\"edges\": edgy.getMapId({'bands': ['B5', 'B4', 'B3'], 'max': 0.5})}\n",
        "\n",
        "center = [37.8694, -121.9785]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 37,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL21heGN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L3RlcnJhaW4ve3p9L3t4fS97eX0uanBnJywKICAgICAgICB7CiAgICAgICAgImF0dHJpYnV0aW9uIjogbnVsbCwKICAgICAgICAiZGV0ZWN0UmV0aW5hIjogZmFsc2UsCiAgICAgICAgIm1heE5hdGl2ZVpvb20iOiAxOCwKICAgICAgICAibWF4Wm9vbSI6IDE4LAogICAgICAgICJtaW5ab29tIjogMCwKICAgICAgICAibm9XcmFwIjogZmFsc2UsCiAgICAgICAgIm9wYWNpdHkiOiAxLAogICAgICAgICJzdWJkb21haW5zIjogImFiYyIsCiAgICAgICAgInRtcyI6IGZhbHNlCn0pLmFkZFRvKG1hcF83NTY5ZjhiMjQyMTk0NTkyOTZiN2M2Y2UxYzE5MThiZik7CiAgICB2YXIgdGlsZV9sYXllcl84ZmFmZWJlMWM1Yjg0NWQ4OWE1ZjQ2NmM2NjU0N2ZmNiA9IEwudGlsZUxheWVyKAogICAgICAgICdodHRwczovL2VhcnRoZW5naW5lLmdvb2dsZWFwaXMuY29tL21hcC8xMzEzMTg1OGFmNDk3ZTM3ZjYwY2U2ZTY5MWQ4MWJkMC97en0ve3h9L3t5fT90b2tlbj03YzBiNzk4MDk4OTY3ODZjN2VlMjlmNWIzYWVjZWI1NycsCiAgICAgICAgewogICAgICAgICJhdHRyaWJ1dGlvbiI6ICJHb29nbGUgRWFydGggRW5naW5lIiwKICAgICAgICAiZGV0ZWN0UmV0aW5hIjogZmFsc2UsCiAgICAgICAgIm1heE5hdGl2ZVpvb20iOiAxOCwKICAgICAgICAibWF4Wm9vbSI6IDE4LAogICAgICAgICJtaW5ab29tIjogMCwKICAgICAgICAibm9XcmFwIjogZmFsc2UsCiAgICAgICAgIm9wYWNpdHkiOiAxLAogICAgICAgICJzdWJkb21haW5zIjogImFiYyIsCiAgICAgICAgInRtcyI6IGZhbHNlCn0pLmFkZFRvKG1hcF83NTY5ZjhiMjQyMTk0NTkyOTZiN2M2Y2UxYzE5MThiZik7CiAgICAKICAgICAgICAgICAgdmFyIGxheWVyX2NvbnRyb2xfMDZjZmRlZDA3MDA3NDI5MDlmZWQwOTMyMDBmNjA2YjcgPSB7CiAgICAgICAgICAgICAgICBiYXNlX2xheWVycyA6IHsgInN0YW1lbnRlcnJhaW4iIDogdGlsZV9sYXllcl8yZGYzNmU2YmJiZGY0Zjk2YWFiYjEyZDA0YzM3ZDc2OCwgfSwKICAgICAgICAgICAgICAgIG92ZXJsYXlzIDogeyAiZWRnZXMiIDogdGlsZV9sYXllcl84ZmFmZWJlMWM1Yjg0NWQ4OWE1ZjQ2NmM2NjU0N2ZmNiwgfQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfMDZjZmRlZDA3MDA3NDI5MDlmZWQwOTMyMDBmNjA2YjcuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzA2Y2ZkZWQwNzAwNzQyOTA5ZmVkMDkzMjAwZjYwNmI3Lm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfNzU2OWY4YjI0MjE5NDU5Mjk2YjdjNmNlMWMxOTE4YmYpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd1886e6a0>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 37
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wAc-Mdiz7RjG",
        "colab_type": "text"
      },
      "source": [
        "Note the format specifier in the visualization parameters. Earth Engine sends display tiles to the Code Editor in JPEG format for efficiency, however edge tiles are sent in PNG format to handle transparency of pixels outside the image boundary. When a visual discontinuity results, setting the format to PNG results in a consistent display. The result of convolving with the Laplacian edge detection kernel should look something like to figure on top.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VEnanydb7djI",
        "colab_type": "text"
      },
      "source": [
        "There are also anisotropic edge detection kernels (e.g. Sobel, Prewitt, Roberts), the direction of which can be changed with kernel.rotate(). Other low pass kernels include a Gaussian kernel and kernels of various shape with uniform weights. To create kernels with arbitrarily defined weights and shape, use ee.Kernel.fixed(). For example, this code creates a 9x9 kernel of 1’s with a zero in the middle"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qb_fqctG8Bfl",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 289
        },
        "outputId": "7f6effd5-2bb7-4371-91af-49004bbaeb16"
      },
      "source": [
        "from pprint import pprint\n",
        "# Create a list of weights for a 9x9 kernel.\n",
        "lista = [1, 1, 1, 1, 1, 1, 1, 1, 1]\n",
        "# The center of the kernel is zero.\n",
        "centerList = [1, 1, 1, 1, 0, 1, 1, 1, 1]\n",
        "# Assemble a list of lists: the 9x9 kernel weights as a 2-D matrix.\n",
        "lists = [lista, lista, lista, lista, centerList, lista, lista, lista, lista]\n",
        "# Create the kernel from the weights.\n",
        "kernel = ee.Kernel.fixed(9, 9, lists, -4, -4, False)\n",
        "pprint(kernel.getInfo())"
      ],
      "execution_count": 40,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "{'center': [4, 4],\n",
            " 'height': 9,\n",
            " 'type': 'Kernel.fixed',\n",
            " 'weights': '\\n'\n",
            "            '  [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\\n'\n",
            "            '  [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\\n'\n",
            "            '  [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\\n'\n",
            "            '  [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\\n'\n",
            "            '  [1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0]\\n'\n",
            "            '  [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\\n'\n",
            "            '  [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\\n'\n",
            "            '  [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\\n'\n",
            "            '  [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]',\n",
            " 'width': 9,\n",
            " 'x': 4,\n",
            " 'y': 4}\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "M2ltWjMZ8c3j",
        "colab_type": "text"
      },
      "source": [
        "# 7. Morphological Operations"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zaCXHwaI8h3L",
        "colab_type": "text"
      },
      "source": [
        "Earth Engine implements morphological operations as focal operations, specifically focal_max(), focal_min(), focal_median(), and focal_mode() instance methods in the Image class. (These are shortcuts for the more general reduceNeighborhood(), which can input the pixels in a kernel to any reducer with a numeric output. See this page for more information on reducing neighborhoods). The morphological operators are useful for performing operations such as erosion, dilation, opening and closing. For example, to perform an opening operation, use focal_min() followed by focal_max()."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8VVPRBs281b2",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "e1cbd1bb-13d8-47c2-db32-4d952ad471f8"
      },
      "source": [
        "# Load a Landsat 8 image, select the NIR band, threshold, display.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318').select(4).gt(0.2);\n",
        "\n",
        "# Define a kernel.\n",
        "kernel = ee.Kernel.circle(radius=1)\n",
        "\n",
        "# Perform an erosion followed by a dilation, display.\n",
        "opened = image.focal_min(kernel=kernel, iterations=2).focal_max(kernel=kernel, iterations=2)\n",
        "\n",
        "tiles = {'NIR threshold': image.getMapId(),\n",
        "         'opened'       : opened.getMapId()}\n",
        "\n",
        "center = [37.5010, -122.1899]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 41,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtl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heXMgOiB7ICJOSVIgdGhyZXNob2xkIiA6IHRpbGVfbGF5ZXJfZTY2ZTBlOWZjOGJmNDE3N2E5M2M4OWViMDFjYmFmMDYsIm9wZW5lZCIgOiB0aWxlX2xheWVyXzhkZDJiMzU4ZDc1NzRiNzhhNmIzN2UzZGYwODgxYzRmLCB9CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF9mMWY4N2I5YjUwNjk0ZjJkOWRhN2JmZGEyMGQ1NDQ4OS5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfZjFmODdiOWI1MDY5NGYyZDlkYTdiZmRhMjBkNTQ0ODkub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7cG9zaXRpb246ICd0b3ByaWdodCcsCiAgICAgICAgICAgICAgICAgY29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF85ODRjZDAzZTE1YjI0ZTliOTVhMWM4ZWM4ZWE2YWY3Zik7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd18899f28>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 41
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IVw7b3fb-K6l",
        "colab_type": "text"
      },
      "source": [
        "Note that in the previous example, a kernel argument is provided to the morphological operator. The pixels covered by non-zero elements of the kernel are used in the computation. The iterations argument indicates how many times to apply the operator."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wt2yKCqp-5KE",
        "colab_type": "text"
      },
      "source": [
        "# 8. Gradients"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "p-hKQ4H1_Aod",
        "colab_type": "text"
      },
      "source": [
        "You can compute the gradient of each band of an image with image.gradient(). For example, the following code computes the gradient magnitude and direction of the Landsat 8 panchromatic band"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "RZ_FhBMs_Dfu",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "c95080ac-ed78-431b-b64f-2b8186ee4b25"
      },
      "source": [
        "# Load a Landsat 8 image and select the panchromatic band.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318').select('B8');\n",
        "\n",
        "# Compute the image gradient in the X and Y directions.\n",
        "xyGrad = image.gradient();\n",
        "\n",
        "# Compute the magnitude of the gradient.\n",
        "gradient = xyGrad.select('x').pow(2).add(xyGrad.select('y').pow(2)).sqrt();\n",
        "\n",
        "# Compute the direction of the gradient.\n",
        "direction = xyGrad.select('y').atan2(xyGrad.select('x'));\n",
        "\n",
        "# Display the results.\n",
        "tiles = {\n",
        "    'direction': direction.getMapId({'min': -2, 'max': 2}),\n",
        "    'gradient' : opened.getMapId({'min': -7, 'max': 7})\n",
        "}\n",
        "\n",
        "center = [37.7295, -122.054]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 42,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1m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gICAgICAibWF4TmF0aXZlWm9vbSI6IDE4LAogICAgICAgICJtYXhab29tIjogMTgsCiAgICAgICAgIm1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMiOiAiYWJjIiwKICAgICAgICAidG1zIjogZmFsc2UKfSkuYWRkVG8obWFwXzVkNGI0MzZlYTEzYjRiMzE4YjliNGRkMDMxYmI2NDdmKTsKICAgIAogICAgICAgICAgICB2YXIgbGF5ZXJfY29udHJvbF85ZDQzNTRkMDliNTQ0YjEzYjM2MGQxMDIwMWY0OWZkMiA9IHsKICAgICAgICAgICAgICAgIGJhc2VfbGF5ZXJzIDogeyAic3RhbWVudGVycmFpbiIgOiB0aWxlX2xheWVyX2YwNDk5MmUxNzIwMTQ4MmRiMTRjODJkODYyNjg3Mjg5LCB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiB7ICJkaXJlY3Rpb24iIDogdGlsZV9sYXllcl8wZmE5MmE3MWE3Yzg0MjJkOWQ1YjFiZWNhMmEyODk4ZSwiZ3JhZGllbnQiIDogdGlsZV9sYXllcl80N2UzYWNmZGYwYjE0NmQ4YTNmMGZiODJkOWQzMzhjZCwgfQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfOWQ0MzU0ZDA5YjU0NGIxM2IzNjBkMTAyMDFmNDlmZDIuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzlkNDM1NGQwOWI1NDRiMTNiMzYwZDEwMjAxZjQ5ZmQyLm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfNWQ0YjQzNmVhMTNiNGIzMThiOWI0ZGQwMzFiYjY0N2YpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd1887f9b0>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 42
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WNudwwQbEl7J",
        "colab_type": "text"
      },
      "source": [
        "# 9. Edge Detection"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ls450E2xEpJU",
        "colab_type": "text"
      },
      "source": [
        "Edge detection is applicable to a wide range of image processing tasks. In addition to the edge detection kernels described in the convolutions section, there are several specialized edge detection algorithms in Earth Engine. The Canny edge detection algorithm (Canny 1986) uses four separate filters to identify the diagonal, vertical, and horizontal edges. The calculation extracts the first derivative value for the horizontal and vertical directions and computes the gradient magnitude. Gradients of smaller magnitude are suppressed. To eliminate high-frequency noise, optionally pre-filter the image with a Gaussian kernel. \n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4G4Xe5KrE3A4",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "c63c38d3-33a0-4628-9a3b-d9f7f3e4290f"
      },
      "source": [
        "# Load a Landsat 8 image, select the panchromatic band.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318').select('B8')\n",
        "\n",
        "canny = ee.Algorithms.CannyEdgeDetector(image=image, threshold=10, sigma=1);\n",
        "\n",
        "# Display the results.\n",
        "tiles = {'canny': canny.getMapId()}\n",
        "\n",
        "center = [37.7295, -122.054]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 43,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL21heGNkbi5ib290c3RyYXBjZG4uY29tL2Jvb3RzdH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ICAgICAiYXR0cmlidXRpb24iOiBudWxsLAogICAgICAgICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAgICAgICAibWF4TmF0aXZlWm9vbSI6IDE4LAogICAgICAgICJtYXhab29tIjogMTgsCiAgICAgICAgIm1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMiOiAiYWJjIiwKICAgICAgICAidG1zIjogZmFsc2UKfSkuYWRkVG8obWFwXzA3YzUyNTIxODIwNTRlNTlhMWY4MDkyMjUzMWZjOGJmKTsKICAgIHZhciB0aWxlX2xheWVyXzdjNWNhOWRkNGJkMjQ0NWU5ZWE5NjA4ZjNhMTViNThlID0gTC50aWxlTGF5ZXIoCiAgICAgICAgJ2h0dHBzOi8vZWFydGhlbmdpbmUuZ29vZ2xlYXBpcy5jb20vbWFwLzU1ZTMwMTE5MDE3ZWUxOGNmYzZhZGM0YTVhYTIwNDdhL3t6fS97eH0ve3l9P3Rva2VuPWQzNTFlYTRmMGYzZjU1NmU0MjYwZjU3YmZlNTkyODUyJywKICAgICAgICB7CiAgICAgICAgImF0dHJpYnV0aW9uIjogIkdvb2dsZSBFYXJ0aCBFbmdpbmUiLAogICAgICAgICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAgICAgICAibWF4TmF0aXZlWm9vbSI6IDE4LAogICAgICAgICJtYXhab29tIjogMTgsCiAgICAgICAgIm1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMiOiAiYWJjIiwKICAgICAgICAidG1zIjogZmFsc2UKfSkuYWRkVG8obWFwXzA3YzUyNTIxODIwNTRlNTlhMWY4MDkyMjUzMWZjOGJmKTsKICAgIAogICAgICAgICAgICB2YXIgbGF5ZXJfY29udHJvbF84YjUwNTgzNThlNzg0NTY0YjRhODI5MmM0MmE1ZDM5NyA9IHsKICAgICAgICAgICAgICAgIGJhc2VfbGF5ZXJzIDogeyAic3RhbWVudGVycmFpbiIgOiB0aWxlX2xheWVyXzc5NzExNWI1NDU4MjRiNjBhMjJkMWQyZWVjN2FlNWFjLCB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiB7ICJjYW5ueSIgOiB0aWxlX2xheWVyXzdjNWNhOWRkNGJkMjQ0NWU5ZWE5NjA4ZjNhMTViNThlLCB9CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF84YjUwNTgzNThlNzg0NTY0YjRhODI5MmM0MmE1ZDM5Ny5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfOGI1MDU4MzU4ZTc4NDU2NGI0YTgyOTJjNDJhNWQzOTcub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7cG9zaXRpb246ICd0b3ByaWdodCcsCiAgICAgICAgICAgICAgICAgY29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF8wN2M1MjUyMTgyMDU0ZTU5YTFmODA5MjI1MzFmYzhiZik7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd1880c630>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 43
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Emh8HV0iGITg",
        "colab_type": "text"
      },
      "source": [
        "Note that the threshold parameter determines the minimum gradient magnitude and the sigma parameter is the standard deviation (SD) of a Gaussian pre-filter to remove high-frequency noise. For line extraction from an edge detector, Earth Engine implements the Hough transform (Duda and Hart 1972). Now extract lines from the Canny detector."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QVBFGPpTGMXg",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "87eff365-d531-4e80-c7f8-de5bb5c0edf7"
      },
      "source": [
        "# Perform Hough transform of the Canny result and display.\n",
        "hough = ee.Algorithms.HoughTransform(canny, 256, 600, 100);\n",
        "\n",
        "# Display the results.\n",
        "tiles = {'hough': hough.getMapId()}\n",
        "\n",
        "center = [37.7295, -122.054]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 46,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgIC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FbmdpbmUiLAogICAgICAgICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAgICAgICAibWF4TmF0aXZlWm9vbSI6IDE4LAogICAgICAgICJtYXhab29tIjogMTgsCiAgICAgICAgIm1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMiOiAiYWJjIiwKICAgICAgICAidG1zIjogZmFsc2UKfSkuYWRkVG8obWFwXzE4MTdjMmU3YTYyZjRjNzk4NzZjNmY1Y2Q3ODdjMWJiKTsKICAgIAogICAgICAgICAgICB2YXIgbGF5ZXJfY29udHJvbF9jNTU5MGM4MjkxMjI0MmNmYjNlYWJkYTc3NzgyNjk1YyA9IHsKICAgICAgICAgICAgICAgIGJhc2VfbGF5ZXJzIDogeyAic3RhbWVudGVycmFpbiIgOiB0aWxlX2xheWVyXzBmYTk2MzNiMGFkYzRiYjhhMWIxZjlhZjlkMDUzYzUxLCB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiB7ICJob3VnaCIgOiB0aWxlX2xheWVyX2FhMTMzZWU1YjhhNTQ1YTNiNDk2ZTg0ZDZjOTBkYjc5LCB9CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF9jNTU5MGM4MjkxMjI0MmNmYjNlYWJkYTc3NzgyNjk1Yy5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfYzU1OTBjODI5MTIyNDJjZmIzZWFiZGE3Nzc4MjY5NWMub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7cG9zaXRpb246ICd0b3ByaWdodCcsCiAgICAgICAgICAgICAgICAgY29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF8xODE3YzJlN2E2MmY0Yzc5ODc2YzZmNWNkNzg3YzFiYik7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd1882f7b8>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 46
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2ElQmG-qGomg",
        "colab_type": "text"
      },
      "source": [
        "Another specialized algorithm in Earth Engine is zeroCrossing(). A zero-crossing is defined as any pixel where the right, bottom, or diagonal bottom-right pixel has the opposite sign. If any of these pixels is of opposite sign, the current pixel is set to 1 (zero-crossing); otherwise it's set to zero. To detect edges, the zero-crossings algorithm can be applied to an estimate of the image second derivative. The following demonstrates using zeroCrossing() for edge detection."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kWgdQrCiGsdq",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "f1f73c2e-76b6-4e48-f05b-72b28f5f7779"
      },
      "source": [
        "# Load a Landsat 8 image, select the panchromatic band.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318').select('B8')\n",
        "\n",
        "# Define a \"fat\" Gaussian kernel.\n",
        "fat = ee.Kernel.gaussian(\n",
        "  radius=3,\n",
        "  sigma=3,\n",
        "  units='pixels',\n",
        "  normalize=True,\n",
        "  magnitude=-1\n",
        ")\n",
        "\n",
        "# Define a \"skinny\" Gaussian kernel.\n",
        "skinny = ee.Kernel.gaussian(\n",
        "  radius=3,\n",
        "  sigma=1,\n",
        "  units='pixels',\n",
        "  normalize=True,\n",
        ")\n",
        "\n",
        "# Compute a difference-of-Gaussians (DOG) kernel.\n",
        "dog = fat.add(skinny)\n",
        "\n",
        "# Compute the zero crossings of the second derivative, display.\n",
        "zeroXings = image.convolve(dog).zeroCrossing()\n",
        "\n",
        "# Display the results.\n",
        "tiles = {\n",
        "    'image': image.getMapId({'max': 12000}),\n",
        "    'zero crossings': zeroXings.updateMask(zeroXings).getMapId({'palette': 'FF0000'})\n",
        "}\n",
        "\n",
        "center = [37.7295, -122.054]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 47,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjw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lcmxheXMgOiB7ICJpbWFnZSIgOiB0aWxlX2xheWVyXzNiOTc1NTBkYzc1MzRiZTA5M2YxZGMzNWVhYzBkMmU3LCJ6ZXJvIGNyb3NzaW5ncyIgOiB0aWxlX2xheWVyXzFjMDJkMDAzMGQxNjQwY2M5MDQ2ZTA1ODY2MDQzYWUyLCB9CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF8wNDc2MjI2ZmNjOWI0YTkwOTE2OTBmMWJjM2E0YzVjOC5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfMDQ3NjIyNmZjYzliNGE5MDkxNjkwZjFiYzNhNGM1Yzgub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7cG9zaXRpb246ICd0b3ByaWdodCcsCiAgICAgICAgICAgICAgICAgY29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF8yZGQzMWE1NzIwNDE0ZmY3ODc5MzI0NzAxOGFkMmUzZSk7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd1886ed30>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 47
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "u6dJ8oM6GofZ",
        "colab_type": "text"
      },
      "source": [
        "Zero-crossings output (red) with the Landsat 8 panchromatic band in the background for an area near the San Francisco, California airport (right)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "P3AFSmaXIe_R",
        "colab_type": "text"
      },
      "source": [
        "# 10. Spectral Transformations"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kM52sIVDIpmg",
        "colab_type": "text"
      },
      "source": [
        "There are several spectral transformation methods in Earth Engine. These include instance methods on images such as normalizedDifference(), unmix(), rgbToHsv() and hsvToRgb(). The latter two methods are useful for pan sharpening."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "IUILJe_oIpGp",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "eab15651-89fd-4a11-842a-0db025fa0811"
      },
      "source": [
        "# Load a Landsat 8 top-of-atmosphere reflectance image.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n",
        "\n",
        "# Convert the RGB bands to the HSV color space.\n",
        "hsv = image.select(['B4', 'B3', 'B2']).rgbToHsv()\n",
        "\n",
        "# Swap in the panchromatic band and convert back to RGB.\n",
        "sharpened = ee.Image.cat([\n",
        "  hsv.select('hue'), hsv.select('saturation'), image.select('B8')\n",
        "]).hsvToRgb()\n",
        "\n",
        "# Display the results.\n",
        "tiles = {\n",
        "    'rgb': image.getMapId({'bands': ['B4', 'B3', 'B2'], \n",
        "                           'min': 0, \n",
        "                           'max': 0.25, \n",
        "                           'gamma': [1.1, 1.1, 1]}),\n",
        "    'pan-sharpened': sharpened.getMapId({'min': 0, \n",
        "                                         'max': 0.25, \n",
        "                                         'gamma': [1.3, 1.3, 1.3]})\n",
        "}\n",
        "\n",
        "center = [37.76664, -122.44829]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 48,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFy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7cG9zaXRpb246ICd0b3ByaWdodCcsCiAgICAgICAgICAgICAgICAgY29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF82ZjMyNDU2YWMxN2Q0OTkxYTMzMjhlOGFjMzg4MGM4Yyk7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd188ac400>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 48
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9YI39K8tLy9R",
        "colab_type": "text"
      },
      "source": [
        "Spectral unmixing is implemented in Earth Engine as the image.unmix() method. (For more flexible methods, see the Array Transformations page). The following is an example of unmixing Landsat 5 with predetermined urban, vegetation and water endmembers."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8Ysg5KhUL5Pn",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "5253e456-40cd-45d6-c7bb-f6a8d652bd06"
      },
      "source": [
        "# Load a Landsat 5 image and select the bands we want to unmix.\n",
        "bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7'];\n",
        "image = ee.Image('LANDSAT/LT05/C01/T1/LT05_044034_20080214').select(bands)\n",
        "\n",
        "# Define spectral endmembers.\n",
        "urban = [88, 42, 48, 38, 86, 115, 59]\n",
        "veg = [50, 21, 20, 35, 50, 110, 23]\n",
        "water = [51, 20, 14, 9, 7, 116, 4]\n",
        "\n",
        "# Unmix the image.\n",
        "fractions = image.unmix([urban, veg, water])\n",
        "\n",
        "# Display the results.\n",
        "tiles = {\n",
        "    'image': image.getMapId({'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 128}),\n",
        "    'unmixed': fractions.getMapId()\n",
        "}\n",
        "\n",
        "center = [37.5010, -122.1899]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 49,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlY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FiNDEgPSBMLnRpbGVMYXllcigKICAgICAgICAnaHR0cHM6Ly9zdGFtZW4tdGlsZXMte3N9LmEuc3NsLmZhc3RseS5uZXQvdGVycmFpbi97en0ve3h9L3t5fS5qcGcnLAogICAgICAgIHsKICAgICAgICAiYXR0cmlidXRpb24iOiBudWxsLAogICAgICAgICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAgICAgICAibWF4TmF0aXZlWm9vbSI6IDE4LAogICAgICAgICJtYXhab29tIjogMTgsCiAgICAgICAgIm1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMiOiAiYWJjIiwKICAgICAgICAidG1zIjogZmFsc2UKfSkuYWRkVG8obWFwXzBjN2YzMzc4ZmMyZDQ5YTNhZDY5NWRkM2NhZjEyZDM2KTsKICAgIHZhciB0aWxlX2xheWVyX2NlNzE4YWQyNDhkNzQwMjViOTU4YzllZDVkMjdkNzJhID0gTC50aWxlTGF5ZXIoCiAgICAgICAgJ2h0dHBzOi8vZWFydGhlbmdpbmUuZ29vZ2xlYXBpcy5jb20vbWFwLzhmZjg0ZDE0MDAwYzRlNWEzZDI0YWI2MzBjM2NjMjk4L3t6fS97eH0ve3l9P3Rva2VuPTE3Yzg5MzU5YWYxNWU4YjFhMmM5NzkyOGQ4NWUxNzliJywKICAgICAgICB7CiAgICAgICAgImF0dHJpYnV0aW9uIjogIkdvb2dsZSBFYXJ0aCBFbmdpbmUiLAogICAgICAgICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAgICAgICAibWF4TmF0aXZlWm9vbSI6IDE4LAogICAgICAgICJtYXhab29tIjogMTgsCiAgICAgICAgIm1pblpvb20iOiAwLAogICAgICAgICJub1dyYXAiOiBmYWxzZSwKICAgICAgICAib3BhY2l0eSI6IDEsCiAgICAgICAgInN1YmRvbWFpbnMiOiAiYWJjIiwKICAgICAgICAidG1zIjogZmFsc2UKf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pbGVfbGF5ZXJfNzQxNjI0Zjg3MmQ5NGEwYjk2OThmZjQ0MDA4ZDlhNzEsIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgIEwuY29udHJvbC5sYXllcnMoCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sX2Y0N2QwODdlYzZlODRhYmE4YmY0YjMxMjM5NzM1Y2M0LmJhc2VfbGF5ZXJzLAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF9mNDdkMDg3ZWM2ZTg0YWJhOGJmNGIzMTIzOTczNWNjNC5vdmVybGF5cywKICAgICAgICAgICAgICAgIHtwb3NpdGlvbjogJ3RvcHJpZ2h0JywKICAgICAgICAgICAgICAgICBjb2xsYXBzZWQ6IHRydWUsCiAgICAgICAgICAgICAgICAgYXV0b1pJbmRleDogdHJ1ZQogICAgICAgICAgICAgICAgfSkuYWRkVG8obWFwXzBjN2YzMzc4ZmMyZDQ5YTNhZDY5NWRkM2NhZjEyZDM2KTsKICAgICAgICAgICAgCiAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd18904ef0>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 49
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gvEM-wYMMxlP",
        "colab_type": "text"
      },
      "source": [
        "The unmixing result should look something like figure on top.\n",
        "Landsat 5 imagery unmixed to urban (red), vegetation (green) and water (blue) fractions. San Francisco bay area, California, USA."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3jgKaKuwMzGH",
        "colab_type": "text"
      },
      "source": [
        "# 11. Texture"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uQiVJXeOM5C_",
        "colab_type": "text"
      },
      "source": [
        "Earth Engine has several special methods for estimating spatial texture. When the image is discrete valued (not floating point), you can use image.entropy() to compute the entropy in a neighborhood"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YocySh-AM4tw",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "ec98401a-4a0c-4585-cb9a-75256e3b3637"
      },
      "source": [
        "# Load a high-resolution NAIP image.\n",
        "image = ee.Image('USDA/NAIP/DOQQ/m_3712213_sw_10_1_20140613')\n",
        "\n",
        "# Get the NIR band.\n",
        "nir = image.select('N')\n",
        "\n",
        "# Define a neighborhood with a kernel.\n",
        "square = ee.Kernel.square(radius=4)\n",
        "\n",
        "# Compute entropy and display.\n",
        "entropy = nir.entropy(square)\n",
        "\n",
        "# Display the results.\n",
        "tiles = {\n",
        "    'image': image.getMapId({'max': 255}),\n",
        "    'entropy': entropy.getMapId({'min': 1, 'max': 5, 'palette': ['0000CC', 'CC0000']})\n",
        "}\n",
        "\n",
        "center = [37.769833, -122.466123]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 50,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPS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oKICAgIHZhciBtYXBfNjQzNGZiODViZTdhNGIxZTgxOWVjZDhjMmY2NDQ1NDggPSBMLm1hcCgKICAgICAgICAnbWFwXzY0MzRmYjg1YmU3YTRiMWU4MTllY2Q4YzJmNjQ0NTQ4JywgewogICAgICAgIGNlbnRlcjogWzM3Ljc2OTgzMywgLTEyMi40NjYxMjNdLAogICAgICAgIHpvb206IDEwLAogICAgICAgIG1heEJvdW5kczogYm91bmRzLAogICAgICAgIGxheWVyczogW10sCiAgICAgICAgd29ybGRDb3B5SnVtcDogZmFsc2UsCiAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NywKICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICB9KTsKCgogICAgCiAgICB2YXIgdGlsZV9sYXllcl83MjBlYmI5MjljZGI0MDZlYTRkZWEwZWFmNmIyZTRlOCA9IEwudGlsZUxheWVyKAogICAgICAgICdodHRwczovL3N0YW1lbi10aWxlcy17c30uYS5zc2wuZmFzdGx5Lm5ldC90ZXJyYWluL3t6fS97eH0ve3l9LmpwZycsCiAgICAgICAgewogICAgICAgICJhdHRyaWJ1dGlvbiI6IG51bGwsCiAgICAgICAgImRldGVjdFJldGluYSI6IGZhbHNlLAogICAgICAgICJtYXhOYXRpdmVab29tIjogMTgsCiAgICAgICAgIm1heFpvb20iOiAxOCwKICAgICAgICAibWluWm9vbSI6IDAsCiAgICAgICAgIm5vV3JhcCI6IGZhbHNlLAogICAgICAgICJvcGFjaXR5IjogMSwKICAgICAgICAic3ViZG9tYWlucyI6ICJhYmMiLAogICAgICAgICJ0bXMiOiBmYWxzZQp9KS5hZGRUbyhtYXBfNjQzNGZiODViZTdhNGIxZTgxOWVjZDhjMmY2NDQ1NDgpOwogICAgdmFyIHRpbGVfbGF5ZXJfYzEzZjIwNzc1NzMzNDM3YmEzNjFjNGY0MGI2MzA0N2QgPSBMLnRpbGVMYXllcigKICAgICAgICAnaHR0cHM6Ly9lYXJ0aGVuZ2luZS5nb29nbGVhc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LAogICAgICAgICJ0bXMiOiBmYWxzZQp9KS5hZGRUbyhtYXBfNjQzNGZiODViZTdhNGIxZTgxOWVjZDhjMmY2NDQ1NDgpOwogICAgCiAgICAgICAgICAgIHZhciBsYXllcl9jb250cm9sX2NlZjg2NmQ5N2YzZDQxZTFhNzVmYzM0MDRmYjNiMjJjID0gewogICAgICAgICAgICAgICAgYmFzZV9sYXllcnMgOiB7ICJzdGFtZW50ZXJyYWluIiA6IHRpbGVfbGF5ZXJfNzIwZWJiOTI5Y2RiNDA2ZWE0ZGVhMGVhZjZiMmU0ZTgsIH0sCiAgICAgICAgICAgICAgICBvdmVybGF5cyA6IHsgImltYWdlIiA6IHRpbGVfbGF5ZXJfYzEzZjIwNzc1NzMzNDM3YmEzNjFjNGY0MGI2MzA0N2QsImVudHJvcHkiIDogdGlsZV9sYXllcl9hZWE2NTc4OGZmOWU0MWI2OThmMmU5NGFhOGJiNzk3ZiwgfQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfY2VmODY2ZDk3ZjNkNDFlMWE3NWZjMzQwNGZiM2IyMmMuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sX2NlZjg2NmQ5N2YzZDQxZTFhNzVmYzM0MDRmYjNiMjJjLm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfNjQzNGZiODViZTdhNGIxZTgxOWVjZDhjMmY2NDQ1NDgpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd1893bd30>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 50
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WD7T0FyMNm8t",
        "colab_type": "text"
      },
      "source": [
        "Note that the NIR band is scaled to 8-bits prior to calling entropy() since the entropy computation takes discrete valued inputs. The non-zero elements in the kernel specify the neighborhood.\n",
        "\n",
        "Another way to measure texture is with a gray-level co-occurrence matrix (GLCM). Using the image and kernel from the previous example, compute the GLCM-based contrast as follows."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cUPAQQ_TNriI",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "e2d3dfab-834c-4756-b940-e08b1738466c"
      },
      "source": [
        "# Compute the gray-level co-occurrence matrix (GLCM), get contrast.\n",
        "glcm = nir.glcmTexture(size=4)\n",
        "contrast = glcm.select('N_contrast')\n",
        "\n",
        "# Display the results.\n",
        "tiles = {\n",
        "    'contrast': contrast.getMapId({'min': 0, 'max': 1500, 'palette': ['0000CC', 'CC0000']})\n",
        "}\n",
        "\n",
        "center = [37.769833, -122.466123]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 51,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxz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NGUwZjc0Y2NhOGEzZGI5MGI1NDQ4YzBmOCIgPjwvZGl2Pgo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCiAgICAKICAgICAgICB2YXIgYm91bmRzID0gbnVsbDsKICAgIAoKICAgIHZhciBtYXBfODJjODg5ODRlMGY3NGNjYThhM2RiOTBiNTQ0OGMwZjggPSBMLm1hcCgKICAgICAgICAnbWFwXzgyYzg4OTg0ZTBmNzRjY2E4YTNkYjkwYjU0NDhjMGY4JywgewogICAgICAgIGNlbnRlcjogWzM3Ljc2OTgzMywgLTEyMi40NjYxMjNdLAogICAgICAgIHpvb206IDEwLAogICAgICAgIG1heEJvdW5kczogYm91bmRzLAogICAgICAgIGxheWVyczogW10sCiAgICAgICAgd29ybGRDb3B5SnVtcDogZmFsc2UsCiAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NywKICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICB9KTsKCgogICAgCiAgICB2YXIgdGlsZV9sYXllcl9hY2E4NmY2YjdmODI0YWY4OWM0NWU3ZDRkNzAyN2NhZSA9IEwudGlsZUxheWVyKAogICAgICAgICdodHRwczovL3N0YW1lbi10aWxlcy17c30uYS5zc2wuZmFzdGx5Lm5ldC90ZXJyYWluL3t6fS97eH0ve3l9LmpwZycsCiAgICAgICAgewogICAgICAgICJhdHRyaWJ1dGlvbiI6IG51bGwsCiAgICAgICAgImRldGVjdFJldGluYSI6IGZhbHNlLAogICAgICAgICJtYXhOYXRpdmVab29tIjogMTgsCiAgICAgICAgIm1heFpvb20iOiAxOCwKICAgICAgICAibWluWm9vbSI6IDAsCiAgICAgICAgIm5vV3JhcCI6IGZhbHNlLAogICAgICAgICJvcGFjaXR5IjogMSwKICAgICAgICAic3ViZG9tYWlucyI6ICJhYmMiLAogICAgICAgICJ0bXMiOiBmYWxzZQp9KS5hZGRUbyhtYXBfODJjODg5ODRlMGY3NGNjYThhM2RiOTBiNTQ0OGMwZjgpOwogICAgdmFyIH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250cm9sXzVhN2UzYzQzNzZjODRmYjlhZmM0NjVlMWY2ZDQwMjZkLmJhc2VfbGF5ZXJzLAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF81YTdlM2M0Mzc2Yzg0ZmI5YWZjNDY1ZTFmNmQ0MDI2ZC5vdmVybGF5cywKICAgICAgICAgICAgICAgIHtwb3NpdGlvbjogJ3RvcHJpZ2h0JywKICAgICAgICAgICAgICAgICBjb2xsYXBzZWQ6IHRydWUsCiAgICAgICAgICAgICAgICAgYXV0b1pJbmRleDogdHJ1ZQogICAgICAgICAgICAgICAgfSkuYWRkVG8obWFwXzgyYzg4OTg0ZTBmNzRjY2E4YTNkYjkwYjU0NDhjMGY4KTsKICAgICAgICAgICAgCiAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd189062e8>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 51
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ugKyH8kRONnB",
        "colab_type": "text"
      },
      "source": [
        "Many measures of texture are output by image.glcm(). For a complete reference on the outputs, see Haralick et al. (1973) and Conners et al. (1984).\n",
        "\n",
        "Local measures of spatial association such as Geary’s C (Anselin 1995) can be computed in Earth Engine using image.neighborhoodToBands(). "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "L4hC0eBxOsM7",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "b21d967f-f466-4d61-92fa-5edf02707979"
      },
      "source": [
        "import math\n",
        "# Create a list of weights for a 9x9 kernel.\n",
        "lista = [1, 1, 1, 1, 1, 1, 1, 1, 1]\n",
        "# The center of the kernel is zero.\n",
        "centerList = [1, 1, 1, 1, 0, 1, 1, 1, 1]\n",
        "# Assemble a list of lists: the 9x9 kernel weights as a 2-D matrix.\n",
        "lists = [lista, lista, lista, lista, centerList, lista, lista, lista, lista]\n",
        "# Create the kernel from the weights.\n",
        "# Non-zero weights represent the spatial neighborhood.\n",
        "kernel = ee.Kernel.fixed(9, 9, lists, -4, -4, False)\n",
        "\n",
        "# Convert the neighborhood into multiple bands.\n",
        "neighs = nir.neighborhoodToBands(kernel)\n",
        "\n",
        "# Compute local Geary's C, a measure of spatial association.\n",
        "gearys = nir.subtract(neighs).pow(2).reduce(ee.Reducer.sum()).divide(math.pow(9, 2))\n",
        "\n",
        "# Display the results.\n",
        "tiles = {\n",
        "    \"Geary's C\": gearys.getMapId({'min': 20, 'max': 2500, 'palette': ['0000CC', 'CC0000']})\n",
        "}\n",
        "\n",
        "center = [37.769833, -122.466123]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 52,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM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ZjRjZjJiNmEwOTdhYzE0Y2JjNjk3JywgewogICAgICAgIGNlbnRlcjogWzM3Ljc2OTgzMywgLTEyMi40NjYxMjNdLAogICAgICAgIHpvb206IDEwLAogICAgICAgIG1heEJvdW5kczogYm91bmRzLAogICAgICAgIGxheWVyczogW10sCiAgICAgICAgd29ybGRDb3B5SnVtcDogZmFsc2UsCiAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NywKICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICB9KTsKCgogICAgCiAgICB2YXIgdGlsZV9sYXllcl9mY2I5N2EyMTRkYjE0MTNiOGYyMDE4Yjk4OTE3YzhjZSA9IEwudGlsZUxheWVyKAogICAgICAgICdodHRwczovL3N0YW1lbi10aWxlcy17c30uYS5zc2wuZmFzdGx5Lm5ldC90ZXJyYWluL3t6fS97eH0ve3l9LmpwZycsCiAgICAgICAgewogICAgICAgICJhdHRyaWJ1dGlvbiI6IG51bGwsCiAgICAgICAgImRldGVjdFJldGluYSI6IGZhbHNlLAogICAgICAgICJtYXhOYXRpdmVab29tIjogMTgsCiAgICAgICAgIm1heFpvb20iOiAxOCwKICAgICAgICAibWluWm9vbSI6IDAsCiAgICAgICAgIm5vV3JhcCI6IGZhbHNlLAogICAgICAgICJvcGFjaXR5IjogMSwKICAgICAgICAic3ViZG9tYWlucyI6ICJhYmMiLAogICAgICAgICJ0bXMiOiBmYWxzZQp9KS5hZGRUbyhtYXBfNDkwMzg2Nzk1YWJmNGNmMmI2YTA5N2FjMTRjYmM2OTcpOwogICAgdmFyIHRpbGVfbGF5ZXJfYjExM2VkY2UyZGU4NDhiMTkyYzY5MjU2MGNmYzRlMjYgPSBMLnRpbGVMYXllcigKICAgICAgICAnaHR0cHM6Ly9lYXJ0aGVuZ2luZS5nb29nbGVhcGlzLmNvbS9tYXAvYjU0MDM5NTA0NjA5ODgzODhjNWQ2Y2VhNzVhOTljMmIve3p9L3t4fS97eX0/dG9rZW49NjdiYWMxZmI4MDdm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29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF80OTAzODY3OTVhYmY0Y2YyYjZhMDk3YWMxNGNiYzY5Nyk7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd18899e10>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 52
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TjVevgO7O9Xe",
        "colab_type": "text"
      },
      "source": [
        "For an example of using neighborhood standard deviation to compute image texture, see the [Statistics of Image Neighborhoods](https://developers.google.com/earth-engine/reducers_reduce_neighborhood) page."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1_5_VmRbPb4D",
        "colab_type": "text"
      },
      "source": [
        "# 12. Object-based Methods"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WUfeysAvPhoD",
        "colab_type": "text"
      },
      "source": [
        "For treating landscape elements as objects, Earth Engine contains several methods. Specifically, when an image has distinct patches identified by unique pixel values, use image.connectedPixelCount() to compute the number of pixels in each patch and image.connectedComponents() to label each patch with a unique identifier. The unique identifiers can then be used to enumerate the patches and analyze the distribution of size or some other quality of interest. The following computes the size and unique identifiers of hot patches in a surface temperature image."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nyDUVZvyPyE6",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "5fb1cc99-a429-4cbd-8162-ca05257d65e0"
      },
      "source": [
        "# Load a Landsat 8 image and display the thermal band.\n",
        "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n",
        "\n",
        "# Threshold the thermal band to find \"hot\" objects.\n",
        "hotspots = image.select('B10').gt(303)\n",
        "\n",
        "# Mask \"cold\" pixels.\n",
        "hotspots = hotspots.updateMask(hotspots)\n",
        "\n",
        "# Compute the number of pixels in each patch.\n",
        "patchsize = hotspots.connectedPixelCount(256, False)\n",
        "\n",
        "# Uniquely label the patches and visualize.\n",
        "patchid = hotspots.connectedComponents(ee.Kernel.plus(1), 256)\n",
        "    \n",
        "# Display the results.\n",
        "tiles = {\n",
        "    \"LST\": image.getMapId({'bands': ['B10'], 'min': 270, 'max': 310}),\n",
        "    \"hotspots\": hotspots.getMapId({'palette': 'FF0000'}),\n",
        "    \"patchsize\": patchsize.getMapId(),\n",
        "    \"patches\": patchid.getMapId()\n",
        "}\n",
        "\n",
        "center = [37.5010, -122.1899]\n",
        "Mapdisplay(center, tiles, \"Stamen Terrain\")"
      ],
      "execution_count": 53,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6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ogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfYWNkYzJhYmJhNmExNGM2YjljMTM0OGZjZjcwZDUwOTkpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd187fc240>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 53
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AHg6wTpm4fIc",
        "colab_type": "text"
      },
      "source": [
        "In the previous example, note that the maximum patch size is set to 256 pixels by the arguments to the connectedPixelCount() and connectedComponents() methods. The connectivity is also specified by the arguments, in the former method by a boolean and in the latter method by an ee.Kernel. In this example, only four neighbors are considered for each pixel.\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "a4SthZpi4kYt",
        "colab_type": "text"
      },
      "source": [
        "# 13. Cumulative Cost Mapping"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mzGgoYNK4wVn",
        "colab_type": "text"
      },
      "source": [
        "Use image.cumulativeCost() to compute a cost map where every pixel contains the total cost of the lowest cost path to the nearest source location. This process is useful in a variety of contexts such as habitat analysis (Adriaensen et al. 2003), watershed delineation (Melles et al. 2011) and image segmentation (Falcao et al. 2004). Call the cumulative cost function on an image in which each pixel represents the cost per meter to traverse it. Paths are computed through any of a pixel's eight neighbors. Required inputs include a source image, in which each non-zero pixel represents a potential source (or start of a path), and a maxDistance (in meters) over which to compute paths. The algorithm finds the cumulative cost of all paths less than maxPixels = maxDistance/scale in length, where scale is the pixel resolution, or scale of analysis in Earth Engine.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6_5sW6Gl42h2",
        "colab_type": "text"
      },
      "source": [
        "The following example demonstrates computing least-cost paths across a land cover image.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GZ-1BSQQ44q8",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "07339a84-a0b8-45db-8d4f-4163589d33c4"
      },
      "source": [
        "# A rectangle representing Bangui, Central African Republic.\n",
        "geometry = ee.Geometry.Rectangle([18.5229, 4.3491, 18.5833, 4.4066])\n",
        "\n",
        "# Create a source image where the geometry is 1, everything else is 0.\n",
        "sources = ee.Image().toByte().paint(geometry, 1)\n",
        "\n",
        "# Mask the sources image with itself.\n",
        "sources = sources.updateMask(sources)\n",
        "\n",
        "# The cost data is generated from classes in ESA/GLOBCOVER.\n",
        "cover = ee.Image('ESA/GLOBCOVER_L4_200901_200912_V2_3').select(0)\n",
        "\n",
        "# Classes 60, 80, 110, 140 have cost 1.\n",
        "# Classes 40, 90, 120, 130, 170 have cost 2.\n",
        "# Classes 50, 70, 150, 160 have cost 3.\n",
        "cost = cover.eq(60).Or(cover.eq(80)).Or(cover.eq(110)).Or(cover.eq(140)).multiply(1).add(cover.eq(40).Or(cover.eq(90)).Or(cover.eq(120)).Or(cover.eq(130)).Or(cover.eq(170)).multiply(2).add(cover.eq(50).Or(cover.eq(70)).Or(cover.eq(150)).Or(cover.eq(160)).multiply(3)))\n",
        "\n",
        "# Compute the cumulative cost to traverse the land cover.\n",
        "cumulativeCost = cost.cumulativeCost(\n",
        "  source = sources,\n",
        "  maxDistance = 80 * 1000 # 80 kilometers\n",
        ")\n",
        "\n",
        "dicc = {\n",
        "    'Globcover': cover.getMapId(),\n",
        "    'accumulated cost': cumulativeCost.getMapId({'min': 0, 'max': 5e4}),\n",
        "    \"source geometry\": geometry.getInfo()\n",
        "}\n",
        "\n",
        "# Display the results\n",
        "center = [4.2, 18.71]\n",
        "Mapdisplay(center, dicc, \"Stamen Terrain\", 10)"
      ],
      "execution_count": 55,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsg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Htwb3NpdGlvbjogJ3RvcHJpZ2h0JywKICAgICAgICAgICAgICAgICBjb2xsYXBzZWQ6IHRydWUsCiAgICAgICAgICAgICAgICAgYXV0b1pJbmRleDogdHJ1ZQogICAgICAgICAgICAgICAgfSkuYWRkVG8obWFwXzI3YzVhNzFhYmFmYjRiMDhiZWJkOGY1MmJkZDE3OWQ2KTsKICAgICAgICAgICAgCiAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd18806e48>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 55
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wUtWHg1IwT-E",
        "colab_type": "text"
      },
      "source": [
        "The top figure in which each output pixel represents the accumulated cost to the nearest source. Note that discontinuities can appear in places where the least cost path to the nearest source exceeds maxPixels in length."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZacyAW9jwmOy",
        "colab_type": "text"
      },
      "source": [
        "The cumulative cost to the source pixels, where cost is determined by the land cover categories. Low costs are black, higher costs are white."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "JTwFpEYGw4BB",
        "colab_type": "text"
      },
      "source": [
        "# 14. Registering Images"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "QyWbaWWIQnL5",
        "colab_type": "text"
      },
      "source": [
        "The Earth Engine image registration algorithm is designed to be a final, post-ortho, fine-grained step in aligning images. It is assumed that the images to be registered have already gone through initial alignment stages, so they are already within a few degrees of rotation of one another, and differ by only small translations. The registration uses a “rubber-sheet” technique, allowing local image warping to correct for orthorectification errors and other artifacts from earlier processing. The underlying alignment technique is image correlation, so the bands for the input and reference images must be visually similar in order for the algorithm to compute an accurate alignment."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lxGo2vW2w-hD",
        "colab_type": "text"
      },
      "source": [
        "## Image displacement"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-F_TQkgjQnJS",
        "colab_type": "text"
      },
      "source": [
        "There are two steps to registering an image: Determining the displacement image using **displacement()**, and then applying it with **displace()**. The required inputs are the pair of images to register, and a maximum displacement parameter **(maxOffset)**.\n",
        "\n",
        "The **displacement()** algorithm takes a reference image, a maximum displacement parameter **(maxOffset)**, and two optional parameters that modify the algorithm behaviour. The output is a displacement image with bands **dx** and **dy** which give the X and Y components (in meters) of the displacement vector at each pixel.\n",
        "\n",
        "All bands of the calling and reference images are used for matching during registration, so the number of bands must be exactly equal. The input bands must be visually similar for registration to succeed. If that is not the case, it may be possible to pre-process them (e.g. smoothing, edge detection) to make them appear more similar. The registration computations are performed using a multiscale, coarse-to-fine process, with (multiscale) working projections that depend on three of the projections supplied to the algorithm:"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "o1t55NRHQnGq",
        "colab_type": "text"
      },
      "source": [
        "1.   The default projection of the calling image (Pc)\n",
        "2.   The default projection of the reference image (Pr)\n",
        "3.   The output projection (Po)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qmx9baLtxgGX",
        "colab_type": "text"
      },
      "source": [
        "The highest resolution working projection (*Pw* will be in the CRS of *Pr*, at a scale determined by the coarsest resolution of these 3 projections, to minimize computation. The results from Pr are then resampled to be in the projection specified by the input **'projection'** parameter."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZP-57ygPxs8y",
        "colab_type": "text"
      },
      "source": [
        "The output is a displacement image with the following bands:\n",
        "\n",
        "**dx:**\n",
        "\n",
        "For a given reference image pixel location, this band contains the distance in the Y direction that must be travelled to arrive at the matching location in the calling image. Units are in geodesic meters.\n",
        "\n",
        "**dy:**\n",
        "\n",
        "For a given reference image pixel location, this band contains the distance in the Y direction that must be travelled to arrive at the matching location in the calling image. Units are in geodesic meters.\n",
        "\n",
        "**confidence:**\n",
        "\n",
        "This is a per-pixel estimate of displacement confidence (where 0 is low confidence and 1 is high confidence) based on the correlation scores in regions where valid matches were found. In regions where no matches were found, confidence is estimated from nearby correlations using a Gaussian kernel to provide higher weight to nearby correlations."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "SOKCS_odx-EE",
        "colab_type": "text"
      },
      "source": [
        "The following example computes the magnitude and angle of displacement between two high-resolution Terra Bella images:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7ZiUh3ugyEjp",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "6fa9f794-6957-42c7-f74e-011c2e77cc60"
      },
      "source": [
        "# Load the two images to be registered.\n",
        "image1 = ee.Image('SKYSAT/GEN-A/PUBLIC/ORTHO/MULTISPECTRAL/s01_20150502T082736Z')\n",
        "image2 = ee.Image('SKYSAT/GEN-A/PUBLIC/ORTHO/MULTISPECTRAL/s01_20150305T081019Z')\n",
        "\n",
        "# Use bicubic resampling during registration.\n",
        "image1Orig = image1.resample('bicubic')\n",
        "image2Orig = image2.resample('bicubic')\n",
        "\n",
        "# Choose to register using only the 'R' band.\n",
        "image1RedBand = image1Orig.select('R')\n",
        "image2RedBand = image2Orig.select('R')\n",
        "\n",
        "# Determine the displacement by matching only the 'R' bands.\n",
        "displacement = image2RedBand.displacement(\n",
        "  referenceImage = image1RedBand,\n",
        "  maxOffset  = 50.0,\n",
        "  patchWidth = 100.0\n",
        ")\n",
        "\n",
        "# Compute image offset and direction.\n",
        "offset = displacement.select('dx').hypot(displacement.select('dy'))\n",
        "angle = displacement.select('dx').atan2(displacement.select('dy'))\n",
        "\n",
        "dicc = {\n",
        "    'offset': offset.getMapId({'min':0, 'max': 20}),\n",
        "    'angle': angle.getMapId({'min': -math.pi, 'max': math.pi})\n",
        "}\n",
        "\n",
        "# Display the results\n",
        "center = [0.58, 37.44]\n",
        "Mapdisplay(center, dicc, \"Stamen Terrain\", 15)"
      ],
      "execution_count": 56,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL21heGNkb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xheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfNTMzZTEyOTY1MTM2NDZjMjliZmM4YWViYTg3N2E1ZDkuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzUzM2UxMjk2NTEzNjQ2YzI5YmZjOGFlYmE4NzdhNWQ5Lm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfODU1NDVhMmQ0OWE5NDQzNGIwY2U1ODM0ZGZjOGE3OTYpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd187a4f98>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 56
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Xt-Xj7tVzVzV",
        "colab_type": "text"
      },
      "source": [
        "## Warping an image"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "NFKVWmXmzXHs",
        "colab_type": "text"
      },
      "source": [
        "There are two ways to warp an image to match another image: **displace()** or **register()**. The **displace()** algorithm takes a displacement image having **dx** and dy bands as the first two bands, and warps the image accordingly. The output image will be the result of warping the bands of the input image by the offsets present in the displacement image. Using the displacements computed in the previous example:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dXZhlXp-zeU9",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "7bb24a3d-24cc-4782-86a8-62458ef900f9"
      },
      "source": [
        "# Use the computed displacement to register all original bands.\n",
        "registered = image2Orig.displace(displacement)\n",
        "\n",
        "# Show the results of co-registering the images.\n",
        "visParams = {'bands': ['R', 'G', 'B'], 'max': 4000}\n",
        "\n",
        "dicc = {\n",
        "    'Reference': image1Orig.getMapId(visParams),\n",
        "    'Before Registration': image2Orig.getMapId(visParams),\n",
        "    'After Registration':  registered.getMapId(visParams)\n",
        "}\n",
        "\n",
        "# Display the results\n",
        "coords = [0.58, 37.44]\n",
        "Mapdisplay(coords, dicc, \"Stamen Terrain\", 15)"
      ],
      "execution_count": 57,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd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DcxYTg5MDliZGE0ZDk3NWIyMmMuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sX2M2MGFjNmQ0ZjE5YTQ3MWE4OTA5YmRhNGQ5NzViMjJjLm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfNTBkZGFlOGU3ODQyNDM2YzhhOGNkYjc3ZWI1MzkzZjApOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd187ae1d0>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 57
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Lp6R4VRf0Cli",
        "colab_type": "text"
      },
      "source": [
        "If you don't need the displacement bands, Earth Engine provides the **register()** method, which is a shortcut for calling **displacement()** followed by **displace()**."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "j8LdqnMZ0GTD",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        },
        "outputId": "05392d0b-698e-401d-913b-237c2f092b16"
      },
      "source": [
        "alsoRegistered = image2Orig.register(\n",
        "  referenceImage = image1Orig,\n",
        "  maxOffset = 50.0,\n",
        "  patchWidth = 100.0\n",
        ")\n",
        "\n",
        "dicc = {\n",
        "    'Also Registered': alsoRegistered.getMapId(visParams)\n",
        "}\n",
        "\n",
        "# Display the results\n",
        "coords = [0.58, 37.44]\n",
        "Mapdisplay(coords, dicc, zoom_start= 15)"
      ],
      "execution_count": 58,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL21heGNkbi5ib290c3RyYXBjZG4uY29tL2Jvb3RzdH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ICAgICAgICAgICAgICAgIGJhc2VfbGF5ZXJzIDogeyAib3BlbnN0cmVldG1hcCIgOiB0aWxlX2xheWVyX2M3YTdlYWIyM2ZkYjQyN2E5ZGYzNThkZGVmN2YyNWJjLCB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiB7ICJBbHNvIFJlZ2lzdGVyZWQiIDogdGlsZV9sYXllcl8zZjhiOWU4YWEwMmQ0OGViOTdjYWIxZGI0NzEwZWYzYiwgfQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfMDdlYzI5MTdmYjA4NDQxMmJmMzE4OWM0YzNiMzI0ZGYuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzA3ZWMyOTE3ZmIwODQ0MTJiZjMxODljNGMzYjMyNGRmLm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfNGI1NjI5ZDM0NTAxNDEyYjkzZTY4Nzg4ZmM0OWEwNzcpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7efd187a4048>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 58
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8kvvneFM0pSp",
        "colab_type": "text"
      },
      "source": [
        "In this example, the results of **register()** differ from the results of **displace()**. This is because a different set of bands was used in the two approaches: **register()** always uses all bands of the input images, while the **displacement()** example used only the red band before feeding the result to **displace()**. Note that when multiple bands are used, if band variances are very different this could over-weight the high-variance bands, since the bands are jointly normalized when their spatial correlation scores are combined. This illustrates the importance of selecting band(s) that are visually the most similar when registering. As in the previous example, use **displacement()** and **displace()** for control over which bands are used to compute displacement."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vMCVgBFUp-mc",
        "colab_type": "text"
      },
      "source": [
        "<!--NAVIGATION-->\n",
        " < [Developer's Guide](1_Introduction.ipynb) | [Contents](index.ipynb) |  [ImageCollection](3_eeImageCollection.ipynb)>\n",
        "\n",
        "<a href=\"https://colab.research.google.com/github/csaybar/EEwPython/blob/master/3_eeImageCollection.ipynb\"><img align=\"left\" src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\" title=\"Open and Execute in Google Colaboratory\"></a>"
      ]
    }
  ]
}